3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Animal { public function eat() { echo 'Yummy!'; } } class Plant { public $size = 0; public function grow() { echo 'I\'m level '.++$this->size; } } if (rand(0, 1) == 0) $base = 'Animal'; else $base = 'Plant'; class_alias($base, "LifeformBase"); class Lifeform extends LifeformBase { } var_dump(new Lifeform); // similar for ReflectionClass, you just need to fetch the name // inheritance by anonymous class; also requires an object representing the anonymous class, like Closure is for anonymous functions. function get_base_animal_class() { return new class extends Animal { public $color; public function hiss() { echo 'Hiss!'; } }; } class_alias(get_class(get_base_animal_class()), "AnonBase"); $tiger_class = new class extends AnonBase { public $color = 'orange'; }; var_dump($tiger_class->hiss(), $tiger_class->color);
Output for git.master_jit, rfc.property-hooks
object(Lifeform)#1 (1) { ["size"]=> int(0) } Hiss!NULL string(6) "orange"
Output for git.master
object(Lifeform)#1 (0) { } Hiss!NULL string(6) "orange"

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:
69.63 ms | 406 KiB | 5 Q