3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php namespace foo\bar { class bat { }; function get_declared_classes($in_namespace = null) { if ($in_namespace === null) { return \get_declared_classes(); } if ($in_namespace{0} == '\\') { $in_namespace = substr($in_namespace, 1); } if (substr($in_namespace, -1) != '\\') { $in_namespace .= '\\'; } $filter = new \RegexIterator(new \ArrayIterator(\get_declared_classes()), '/^' .\preg_quote($in_namespace). '.*$/'); return \iterator_to_array($filter); } } namespace foo\bar\baz { class qux { } } namespace { var_dump(\foo\bar\get_declared_classes("foo\\bar")); }
based on E23b1
Output for 7.2.0
array(2) { [157]=> string(11) "foo\bar\bat" [158]=> string(15) "foo\bar\baz\qux" }
Output for 7.1.0 - 7.1.10
array(2) { [156]=> string(11) "foo\bar\bat" [157]=> string(15) "foo\bar\baz\qux" }
Output for 7.0.0 - 7.0.4, 7.0.20
array(2) { [153]=> string(11) "foo\bar\bat" [154]=> string(15) "foo\bar\baz\qux" }
Output for 7.0.6
array(2) { [152]=> string(11) "foo\bar\bat" [153]=> string(15) "foo\bar\baz\qux" }
Output for 7.0.5
array(2) { [133]=> string(11) "foo\bar\bat" [134]=> string(15) "foo\bar\baz\qux" }
Output for 5.6.8 - 5.6.12, 5.6.16 - 5.6.19, 5.6.28
array(2) { [143]=> string(11) "foo\bar\bat" [144]=> string(15) "foo\bar\baz\qux" }
Output for 5.5.24 - 5.5.28, 5.5.31 - 5.5.33, 5.5.35, 5.6.21
array(2) { [142]=> string(11) "foo\bar\bat" [143]=> string(15) "foo\bar\baz\qux" }
Output for 5.6.13 - 5.6.15, 5.6.20
array(2) { [124]=> string(11) "foo\bar\bat" [125]=> string(15) "foo\bar\baz\qux" }
Output for 5.5.29 - 5.5.30, 5.5.34
array(2) { [123]=> string(11) "foo\bar\bat" [124]=> string(15) "foo\bar\baz\qux" }
Output for 5.4.9 - 5.4.45
array(2) { [130]=> string(11) "foo\bar\bat" [131]=> string(15) "foo\bar\baz\qux" }
Output for 5.3.19 - 5.3.29
array(2) { [128]=> string(11) "foo\bar\bat" [129]=> string(15) "foo\bar\baz\qux" }