3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace test; use \Closure; class MyClass { protected Closure $modifier; public function __construct(callable $modifier) { $this->modifier = Closure::fromCallable($modifier); } } class SomeOtherClass { public static function func() { return ['a' => 'b']; } } // this will work fine $a = new MyClass(['\test\SomeOtherClass', 'func']); var_dump($a); // this will cause error $b = new MyClass(['SomeOtherClass', 'func']);
Output for git.master, git.master_jit, rfc.property-hooks
object(test\MyClass)#1 (1) { ["modifier":protected]=> object(Closure)#2 (1) { ["function"]=> string(25) "test\SomeOtherClass::func" } } Fatal error: Uncaught TypeError: test\MyClass::__construct(): Argument #1 ($modifier) must be of type callable, array given, called in /in/pnWYC on line 28 and defined in /in/pnWYC:10 Stack trace: #0 /in/pnWYC(28): test\MyClass->__construct(Array) #1 {main} thrown in /in/pnWYC on line 10
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:
35.48 ms | 406 KiB | 5 Q