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 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
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.
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.1.0 - 8.1.33
object(test\MyClass)#1 (1) { ["modifier":protected]=> object(Closure)#2 (0) { } } 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.

preferences:
118.4 ms | 409 KiB | 5 Q