3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php namespace foo\bar; function get_declared_classes($in_namespace = null) { if ($in_namespace === null) { yield get_declared_classes(); } if ($in_namespace{0} == '\\') { $in_namespace = substr($in_namespace, 1); } if (substr($in_namespace, -1) != '\\') { $in_namespace .= '\\'; } $classes = get_declared_classes(); $filter = new RegexIterator(new ArrayIterator($classes), '/^' .preg_quote($in_namespace). '.*$'); foreach ($filter as $class) { yield $class; } } foreach (get_declared_classes("foo\\bar") as $class) { var_dump($class); }
based on lekjj
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Class 'foo\bar\RegexIterator' not found in /in/NbISH:20 Stack trace: #0 /in/NbISH(26): foo\bar\get_declared_classes('foo\\bar\\') #1 {main} thrown in /in/NbISH on line 20
Process exited with code 255.
Output for 5.5.24 - 5.6.28
Fatal error: Class 'foo\bar\RegexIterator' not found in /in/NbISH on line 20
Process exited with code 255.
Output for 5.4.9 - 5.4.45
Parse error: syntax error, unexpected 'get_declared_classes' (T_STRING) in /in/NbISH on line 8
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected T_STRING in /in/NbISH on line 8
Process exited with code 255.