3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace SomethingElse; class Test{} class Test2{} namespace MyApp\Example; use ReflectionClass; use ReflectionProperty; use SomethingElse\Test; use SomethingElse\Test2 as Alias; class ClassWithTypeHintedProperties { /** @var Test */ public $test; /** @var Alias */ public $alias; } $c = new ClassWithTypeHintedProperties(); $reflection = new ReflectionClass($c); $declared = get_declared_classes(); $usedWithNamespace = []; foreach ($declared as $class) { if (strstr($class, '\\')) { $usedWithNamespace[] = $class; } } var_dump($usedWithNamespace); foreach($reflection->getProperties(ReflectionProperty::IS_PUBLIC) as $p) { $comment = $p->getDocComment(); $comment = str_replace('/** @var', '', $comment); $comment = str_replace(' */', '', $comment); $comment = trim($comment); foreach ($usedWithNamespace as $class) { if (strstr($comment, $class)) { $comment = $class; echo $class."\n"; } } }
Output for git.master, git.master_jit
array(11) { [0]=> string(18) "Random\RandomError" [1]=> string(30) "Random\BrokenRandomEngineError" [2]=> string(22) "Random\RandomException" [3]=> string(21) "Random\Engine\Mt19937" [4]=> string(33) "Random\Engine\PcgOneseq128XslRr64" [5]=> string(32) "Random\Engine\Xoshiro256StarStar" [6]=> string(20) "Random\Engine\Secure" [7]=> string(17) "Random\Randomizer" [8]=> string(18) "SomethingElse\Test" [9]=> string(19) "SomethingElse\Test2" [10]=> string(43) "MyApp\Example\ClassWithTypeHintedProperties" }
Output for rfc.property-hooks
array(12) { [0]=> string(18) "Random\RandomError" [1]=> string(30) "Random\BrokenRandomEngineError" [2]=> string(22) "Random\RandomException" [3]=> string(21) "Random\Engine\Mt19937" [4]=> string(33) "Random\Engine\PcgOneseq128XslRr64" [5]=> string(32) "Random\Engine\Xoshiro256StarStar" [6]=> string(20) "Random\Engine\Secure" [7]=> string(17) "Random\Randomizer" [8]=> string(23) "Random\IntervalBoundary" [9]=> string(18) "SomethingElse\Test" [10]=> string(19) "SomethingElse\Test2" [11]=> string(43) "MyApp\Example\ClassWithTypeHintedProperties" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
73.13 ms | 402 KiB | 8 Q