3v4l.org

run code in 200+ PHP versions simultaneously
<?php declare(strict_types=1); file_put_contents('/tmp/bug2.php', <<<EOT <?php declare(strict_types=1); class myParentClass { const myConst = 'Parent'; } EOT ); require('/tmp/bug2.php'); // Error: mySubClass2 does NOT exist! var_dump( class_exists( 'myClass1', FALSE ), class_exists( 'mySubClass1', FALSE ), class_exists( 'myParentClass', FALSE ), class_exists( 'mySubClass2', FALSE ) ); class myClass1 { const myConst = 'C1'; } class mySubClass1 extends myClass1 { const myConst = 'S1'; } class mySubClass2 extends myParentClass { const myConst = 'S2'; } // Correct: Now mySubClass2 DOES exist! var_dump( class_exists( 'myClass1', FALSE ), class_exists( 'mySubClass1', FALSE ), class_exists( 'myParentClass', FALSE ), class_exists( 'mySubClass2', FALSE ) );
Output for 5.0.0 - 5.2.17, 7.0.0 - 7.3.6
bool(true) bool(true) bool(true) bool(false) bool(true) bool(true) bool(true) bool(true)
Output for 5.3.0 - 5.6.40
Warning: Unsupported declare 'strict_types' in /in/GnDr2 on line 1 Warning: Unsupported declare 'strict_types' in /tmp/bug2.php on line 1 bool(true) bool(true) bool(true) bool(false) bool(true) bool(true) bool(true) bool(true)
Output for 4.4.3 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/GnDr2 on line 23
Process exited with code 255.
Output for 4.4.2
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/GnDr2 on line 24
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/GnDr2 on line 23
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/GnDr2 on line 23
Process exited with code 255.