3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { static public function get_self() { return new self(); } static public function get_static() { return new static(); } } class B extends A {} class C { public function static_get_a_self() { return A::get_self(); } public function static_get_a_static() { return A::get_static(); } public function var_get_a_self() { $a = new A(); return $a->get_self(); } public function var_get_a_static() { $a = new A(); return $a->get_static(); } public function static_get_b_self() { return B::get_self(); } public function static_get_b_static() { return B::get_static(); } public function var_get_b_self() { $b = new B(); return $b->get_self(); } public function var_get_b_static() { $b = new B(); return $b->get_static(); } } $a = new A(); $b = new B(); $c = new C(); echo "Static calls: \n"; echo "B::get_self() ============= " . get_class(B::get_self()) . " | expected A \n"; echo "B::get_static() =========== " . get_class(B::get_static()) . " | expected B \n"; echo "A::get_static() =========== " . get_class(A::get_static()) . " | expected A \n"; echo "\n"; echo "Object Calls on A: \n"; echo '$a->get_self() ============ ' . get_class($a->get_self()) . " | expected A \n"; echo '$a->get_static() ========== ' . get_class($a->get_static()) . " | expected A \n"; echo "\n"; echo "Object Calls on B: \n"; echo '$b->get_self() ============ ' . get_class($b->get_self()) . " | expected A \n"; echo '$b->get_static() ========== ' . get_class($b->get_static()) . " | expected B \n"; echo "\n"; echo "C Object Calls on A: \n"; echo "Internally against A::{call}\n"; echo '$c->static_get_a_self() === ' . get_class($c->static_get_a_self()) . " | expected A \n"; echo '$c->static_get_a_static() = ' . get_class($c->static_get_a_static()) . " | expected A < Whoa! \n"; echo "Internally against \$a = new A();\n"; echo '$c->var_get_a_self() ====== ' . get_class($c->var_get_a_self()) . " | expected A \n"; echo '$c->var_get_a_static() ==== ' . get_class($c->var_get_a_static()) . " | expected A \n"; echo "\n"; echo "C Object Calls on B: \n"; echo "Internally against B::{call}\n"; echo '$c->static_get_b_self() === ' . get_class($c->static_get_b_self()) . " | expected A \n"; echo '$c->static_get_b_static() = ' . get_class($c->static_get_b_static()) . " | expected B < Whoa! \n"; echo "Internally against \$b = new B();\n"; echo '$c->var_get_b_self() ====== ' . get_class($c->var_get_b_self()) . " | expected A \n"; echo '$c->var_get_b_static() ==== ' . get_class($c->var_get_b_static()) . " | expected B \n"; ?>
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Static calls: B::get_self() ============= A | expected A B::get_static() =========== B | expected B A::get_static() =========== A | expected A Object Calls on A: $a->get_self() ============ A | expected A $a->get_static() ========== A | expected A Object Calls on B: $b->get_self() ============ A | expected A $b->get_static() ========== B | expected B C Object Calls on A: Internally against A::{call} $c->static_get_a_self() === A | expected A $c->static_get_a_static() = A | expected A < Whoa! Internally against $a = new A(); $c->var_get_a_self() ====== A | expected A $c->var_get_a_static() ==== A | expected A C Object Calls on B: Internally against B::{call} $c->static_get_b_self() === A | expected A $c->static_get_b_static() = B | expected B < Whoa! Internally against $b = new B(); $c->var_get_b_self() ====== A | expected A $c->var_get_b_static() ==== B | expected B
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_STATIC, expecting T_STRING or T_VARIABLE or '$' in /in/RWRE9 on line 9
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STATIC, expecting T_STRING or T_VARIABLE or '$' in /in/RWRE9 on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/RWRE9 on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/RWRE9 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/RWRE9 on line 4
Process exited with code 255.

preferences:
243.07 ms | 401 KiB | 354 Q