3v4l.org

run code in 300+ PHP versions simultaneously
<?php class foo { function define_new_class($class, $code) { if (!class_exists($class)) { $definition = eval($code); } } function bar() { $new_class = "boo"; $this->define_new_class($new_class, "class $new_class {function far(){echo 'Far method of class '.get_class(\$this);}}"); $obj = new $new_class(); echo "Current class: " . get_class($this) . "\n"; // foo echo "\$obj class: " . get_class($obj) . "\n"; // boo } function lar() { echo "lalalala"; } } $foo = new foo(); $foo->bar(); $b = new boo(); $b->far(); $b->lar();
Output for git.master, git.master_jit, rfc.property-hooks
Current class: foo $obj class: boo Far method of class boo Fatal error: Uncaught Error: Call to undefined method boo::lar() in /in/ceuWv:29 Stack trace: #0 {main} thrown in /in/ceuWv on line 29
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:
50.96 ms | 401 KiB | 8 Q