note 128172 added to reflectionattribute.newinstance
| From: | baptiste at pillot dot fr | Date: | Mon, 30 Jan 2023 11:07:05 +0000 |
| Subject: | note 128172 added to reflectionattribute.newinstance | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220128@lists.php.net to get a copy of this message | ||
Calling ReflectionAttribute::newInstance() using an attribute name that has a matching class without
#[Attribute] will result in an error.
Example :
<?php
class FakeAttribute {}
#[FakeAttribute]
class Test {}
try {
(new ReflectionClass(Test::class))->getAttributes()[0]->newInstance();
}
catch (Error $error) {
echo 'Throwed error ' . get_class($error) . ' with message : ' .
$error->getMessage();
}
?>
This will output :
Throwed error Error with message : Attempting to use non-attribute class "FakeAttribute"
as attribute
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.158.213 (proxied: 37.167.132.212)
----
Manual Page -- https://php.net/manual/en/reflectionattribute.newinstance.php
Edit -- https://main.php.net/note/edit/128172
Del: integrated -- https://main.php.net/note/delete/128172/integrated
Del: useless -- https://main.php.net/note/delete/128172/useless
Del: bad code -- https://main.php.net/note/delete/128172/bad+code
Del: spam -- https://main.php.net/note/delete/128172/spam
Del: non-english -- https://main.php.net/note/delete/128172/non-english
Del: in docs -- https://main.php.net/note/delete/128172/in+docs
Del: other reasons-- https://main.php.net/note/delete/128172
Reject -- https://main.php.net/note/reject/128172
Search -- https://main.php.net/manage/user-notes.php