3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public function get_self() { return new self(); } 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 git.master, git.master_jit, rfc.property-hooks
Static calls: Fatal error: Uncaught Error: Non-static method A::get_self() cannot be called statically in /in/1PecT:59 Stack trace: #0 {main} thrown in /in/1PecT on line 59
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.64 ms | 401 KiB | 8 Q