3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class MyParent { const NAVIGATION = 'nav'; public static function getUri() { static $uri = null; if ($uri === null) { echo 'null<br>'; $uri = 'test '.self::NAVIGATION; } return $uri; } } class FirstChild extends MyParent { } class SecondChild extends MyParent { const NAVIGATION = 'childnav'; } $first = new FirstChild(); $second = new SecondChild(); echo '<pre>', var_export($first->getUri(), true), '</pre>'; echo '<pre>', var_export($second->getUri(), true), '</pre>'; echo '<pre>', var_export($first->getUri(), true), '</pre>'; echo '<pre>', var_export($second->getUri(), true), '</pre>';
based on i94dj
Output for 5.0.0 - 5.6.38, hhvm-3.10.1 - 3.22.0, 7.0.0 - 7.3.0rc3
<pre>null<br>'test nav'</pre><pre>null<br>'test nav'</pre><pre>'test nav'</pre><pre>'test nav'</pre>
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/n4I8I on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/n4I8I on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/n4I8I on line 4
Process exited with code 255.