3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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"; } } }
based on 0v70r
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.2.8
array(3) { [0]=> string(18) "SomethingElse\Test" [1]=> string(19) "SomethingElse\Test2" [2]=> string(43) "MyApp\Example\ClassWithTypeHintedProperties" }
Output for hhvm-3.21.3 - 3.22.0
array(58) { [0]=> string(24) "HH\Asio\WrappedException" [1]=> string(30) "__SystemLib\PharArchiveHandler" [2]=> string(29) "__SystemLib\TarArchiveHandler" [3]=> string(26) "HH\AsyncFunctionWaitHandle" [4]=> string(31) "__SystemLib\DivisionByZeroError" [5]=> string(21) "HH\WaitableWaitHandle" [6]=> string(27) "HH\AsyncGeneratorWaitHandle" [7]=> string(18) "HH\SleepWaitHandle" [8]=> string(29) "__SystemLib\InvariantCallback" [9]=> string(21) "HH\Asio\WrappedResult" [10]=> string(27) "__SystemLib\ArithmeticError" [11]=> string(30) "__SystemLib\ConvertIconvFilter" [12]=> string(31) "__SystemLib\DeflateStreamFilter" [13]=> string(6) "HH\Map" [14]=> string(22) "__SystemLib\ParseError" [15]=> string(25) "HH\Client\TypecheckResult" [16]=> string(35) "__SystemLib\StringRot13StreamFilter" [17]=> string(25) "__SystemLib\ConvertFilter" [18]=> string(30) "__SystemLib\StreamFilterBucket" [19]=> string(16) "HH\FactTypeFlags" [20]=> string(27) "__SystemLib\ChunkedInflator" [21]=> string(7) "HH\Pair" [22]=> string(17) "HH\AsyncGenerator" [23]=> string(17) "__SystemLib\Error" [24]=> string(28) "__SystemLib\ArchiveEntryType" [25]=> string(23) "HH\RescheduleWaitHandle" [26]=> string(6) "HH\Set" [27]=> string(37) "__SystemLib\StringToUpperStreamFilter" [28]=> string(21) "HH\InvariantException" [29]=> string(13) "HH\WaitHandle" [30]=> string(19) "__SystemLib\PhpInfo" [31]=> string(20) "HH\TypeStructureKind" [32]=> string(28) "__SystemLib\MethCallerHelper" [33]=> string(9) "HH\ImmSet" [34]=> string(32) "HH\ExternalThreadEventWaitHandle" [35]=> string(9) "HH\ImmMap" [36]=> string(26) "__SystemLib\AssertionError" [37]=> string(31) "__SystemLib\InflateStreamFilter" [38]=> string(14) "HH\BuiltinEnum" [39]=> string(31) "__SystemLib\HH\Client\CacheKeys" [40]=> string(28) "__SystemLib\ArchiveEntryStat" [41]=> string(9) "HH\Vector" [42]=> string(25) "HH\Client\TypecheckStatus" [43]=> string(9) "HH\Shapes" [44]=> string(22) "HH\ConditionWaitHandle" [45]=> string(22) "HH\ResumableWaitHandle" [46]=> string(37) "__SystemLib\StringToLowerStreamFilter" [47]=> string(23) "__SystemLib\Bzip2Filter" [48]=> string(12) "HH\ImmVector" [49]=> string(21) "__SystemLib\TypeError" [50]=> string(21) "HH\AwaitAllWaitHandle" [51]=> string(36) "__SystemLib\SessionForwardingHandler" [52]=> string(19) "HH\StaticWaitHandle" [53]=> string(29) "__SystemLib\ZipArchiveHandler" [54]=> string(26) "__SystemLib\ArchiveHandler" [55]=> string(43) "MyApp\Example\ClassWithTypeHintedProperties" [56]=> string(19) "SomethingElse\Test2" [57]=> string(18) "SomethingElse\Test" }
Output for hhvm-3.18.5
array(57) { [0]=> string(24) "HH\Asio\WrappedException" [1]=> string(30) "__SystemLib\PharArchiveHandler" [2]=> string(29) "__SystemLib\TarArchiveHandler" [3]=> string(26) "HH\AsyncFunctionWaitHandle" [4]=> string(31) "__SystemLib\DivisionByZeroError" [5]=> string(21) "HH\WaitableWaitHandle" [6]=> string(27) "HH\AsyncGeneratorWaitHandle" [7]=> string(18) "HH\SleepWaitHandle" [8]=> string(29) "__SystemLib\InvariantCallback" [9]=> string(21) "HH\Asio\WrappedResult" [10]=> string(27) "__SystemLib\ArithmeticError" [11]=> string(30) "__SystemLib\ConvertIconvFilter" [12]=> string(31) "__SystemLib\DeflateStreamFilter" [13]=> string(6) "HH\Map" [14]=> string(22) "__SystemLib\ParseError" [15]=> string(25) "HH\Client\TypecheckResult" [16]=> string(35) "__SystemLib\StringRot13StreamFilter" [17]=> string(25) "__SystemLib\ConvertFilter" [18]=> string(30) "__SystemLib\StreamFilterBucket" [19]=> string(16) "HH\FactTypeFlags" [20]=> string(27) "__SystemLib\ChunkedInflator" [21]=> string(7) "HH\Pair" [22]=> string(17) "HH\AsyncGenerator" [23]=> string(17) "__SystemLib\Error" [24]=> string(23) "HH\RescheduleWaitHandle" [25]=> string(6) "HH\Set" [26]=> string(37) "__SystemLib\StringToUpperStreamFilter" [27]=> string(21) "HH\InvariantException" [28]=> string(13) "HH\WaitHandle" [29]=> string(19) "__SystemLib\PhpInfo" [30]=> string(20) "HH\TypeStructureKind" [31]=> string(28) "__SystemLib\MethCallerHelper" [32]=> string(9) "HH\ImmSet" [33]=> string(32) "HH\ExternalThreadEventWaitHandle" [34]=> string(9) "HH\ImmMap" [35]=> string(26) "__SystemLib\AssertionError" [36]=> string(31) "__SystemLib\InflateStreamFilter" [37]=> string(14) "HH\BuiltinEnum" [38]=> string(31) "__SystemLib\HH\Client\CacheKeys" [39]=> string(28) "__SystemLib\ArchiveEntryStat" [40]=> string(9) "HH\Vector" [41]=> string(25) "HH\Client\TypecheckStatus" [42]=> string(9) "HH\Shapes" [43]=> string(22) "HH\ConditionWaitHandle" [44]=> string(22) "HH\ResumableWaitHandle" [45]=> string(37) "__SystemLib\StringToLowerStreamFilter" [46]=> string(23) "__SystemLib\Bzip2Filter" [47]=> string(12) "HH\ImmVector" [48]=> string(21) "__SystemLib\TypeError" [49]=> string(21) "HH\AwaitAllWaitHandle" [50]=> string(36) "__SystemLib\SessionForwardingHandler" [51]=> string(19) "HH\StaticWaitHandle" [52]=> string(29) "__SystemLib\ZipArchiveHandler" [53]=> string(26) "__SystemLib\ArchiveHandler" [54]=> string(43) "MyApp\Example\ClassWithTypeHintedProperties" [55]=> string(19) "SomethingElse\Test2" [56]=> string(18) "SomethingElse\Test" }