note 127163 added to language.attributes.overview
| From: | ScorpioT1000 at ya dot ru | Date: | Thu, 09 Jun 2022 04:10:00 +0000 |
| Subject: | note 127163 added to language.attributes.overview | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218571@lists.php.net to get a copy of this message | ||
Example attribute for parameters usage:
<?php
#[Attribute]
class MyAttribute
{
public function __construct(
protected string $data = 'default data'
) {
}
}
function myFunction(
#[MyAttribute(data: 'custom data')]
string $myParameter
) {
}
$rAttribute = (new ReflectionFunction('myFunction'))
->getParameters()[0]
->getAttributes()[0];
var_dump($rAttribute);
$attributeInstance = $rAttribute->newInstance();
var_dump($attributeInstance);
?>
Result:
object(ReflectionAttribute)#1 (0) {
}
object(MyAttribute)#2 (1) {
["data":protected]=>
string(11) "custom data"
}
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.12.131 (proxied: 5.227.29.115)
----
Manual Page -- https://php.net/manual/en/language.attributes.overview.php
Edit -- https://main.php.net/note/edit/127163
Del: integrated -- https://main.php.net/note/delete/127163/integrated
Del: useless -- https://main.php.net/note/delete/127163/useless
Del: bad code -- https://main.php.net/note/delete/127163/bad+code
Del: spam -- https://main.php.net/note/delete/127163/spam
Del: non-english -- https://main.php.net/note/delete/127163/non-english
Del: in docs -- https://main.php.net/note/delete/127163/in+docs
Del: other reasons-- https://main.php.net/note/delete/127163
Reject -- https://main.php.net/note/reject/127163
Search -- https://main.php.net/manage/user-notes.php