3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyAttributeBase {} class MyAttribute extends MyAttributeBase {} class C { public function __construct( #[\SensitiveParameter] #[MyAttribute] public string $x, ) {} } new C('hello'); $param = (new ReflectionMethod('C', '__construct'))->getParameters()[0]; spl_autoload_register(function (string $class) { $line = debug_backtrace()[1]['line']; print "Line $line: Trying to autoload $class.\n"; }); $attributes = $param->getAttributes(UnknownClass::class); assert($attributes === []); $attributes = $param->getAttributes(MyAttributeBase::class); assert($attributes === []); $attributes = $param->getAttributes(MyAttributeBase::class, \ReflectionAttribute::IS_INSTANCEOF); assert(count($attributes) === 1); assert($attributes[0]->getName() === MyAttribute::class); $attributes = $param->getAttributes(); assert(count($attributes) === 2); assert($attributes[0]->getName() === SensitiveParameter::class); assert($attributes[1]->getName() === MyAttribute::class); $attributes[0]->newInstance();
Output for 8.2.0 - 8.2.29, 8.3.5 - 8.3.28, 8.4.7 - 8.4.14, 8.5.0
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.32 - 8.1.33
Line 31: Trying to autoload SensitiveParameter. Line 40: Trying to autoload SensitiveParameter. Fatal error: Uncaught Error: Attribute class "SensitiveParameter" not found in /in/I9AZh:40 Stack trace: #0 /in/I9AZh(40): ReflectionAttribute->newInstance() #1 {main} thrown in /in/I9AZh on line 40
Process exited with code 255.

preferences:
69.34 ms | 409 KiB | 5 Q