3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* testNotAcceptedTypeExceptionOutsideAttribute1 */ /** * Docblock */ #[Attribute] function notAcceptedTokenOutsideAttributeTest() {} /* testNotAcceptedTypeExceptionOutsideAttribute2 */ echo 'notAcceptedTokenOutsideAttributeTest'; /* testAcceptedTokens */ #[AttributeName(10), \AnotherAttribute, namespace\ThirdAttribute(self::CONSTANT, 'foo')] function acceptedTokensAttributeTarget() {} /* testFindUnscopedConst */ #[MyAttribute] const UNSCOPED = true; array_map( /* testFindUnscopedClosure */ #[MyAttribute] function($a) { return $a++; }, $array ); /* testFindUnscopedClosureStatic */ $closure = #[MyAttribute] static function($a) {}; array_map( /* testFindUnscopedArrowFunction */ #[MyAttribute] fn($a) => $a++, $array ); /* testFindUnscopedArrowFunctionStatic */ $closure = #[MyAttribute] static fn ($a) => $a * 10; function hasParamAttributes( /* testFindFunctionParameter */ #[MyAttribute] #[AnotherAttribute] $paramA, /* testFindFunctionParameterTypedNullable */ #[MyAttribute] ?int $paramB, /* testFindFunctionParameterTypedUnion */ #[MyAttribute] int|false $paramC, /* testFindFunctionParameterWithRef */ #[MyAttribute] // Unrelated comment &$paramD, /* testFindFunctionParameterWithSpread */ #[MyAttribute] /** docblock */ ...$paramE, /* testFindFunctionParameterAllTogetherNow */ #[MyAttribute] (\Foo|Partial\Bar|namespace\Other)|array &...$paramF, ) {} /* testFindClass */ #[MyAttribute] class classHasAttribute {} /* testFindClassFinal */ #[MyAttribute] /** * Docblock. */ #[AnotherAttribute] final class finalClass {} /* testFindClassReadonly */ #[MyAttribute] readonly class readonlyClass {} /* testFindClassAbstract */ #[MyAttribute] abstract class abstractClass {} /* testFindClassFinalReadonly */ #[MyAttribute] // Unrelated comment. // Another unrelated comment. final readonly class finalReadonlyClass {} /* testFindAnonClass */ $anon = new #[MyAttribute] #[SecondAttribute] class {}; /* testFindAnonClassReadonly */ $anon = new #[MyAttribute] readonly class {}; /* testFindTrait */ #[MyAttribute(10), \Another] trait traitHasAttribute {} /* testFindInterface */ #[MyAttribute] #[AnotherAttributeWithBlankLinesAroundIt( name: VALUE, other_name: VALUE, )]
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Parse error: syntax error, unexpected token "const" in /in/ZGPdg on line 19
Process exited with code 255.

preferences:
159.79 ms | 1067 KiB | 8 Q