note 125889 added to language.attributes.reflection

From: Date: Mon, 08 Mar 2021 08:34:40 +0000
Subject: note 125889 added to language.attributes.reflection
Groups: php.notes 
Request: Send a blank email to php-notes+get-219269@lists.php.net to get a copy of this message
Fetch properties from functions: ---------------------------------------- Function definition with attributes: ---------------------------------------- #[ReadOnly] #[Property(type: 'function', name: 'Hello')] function Hello() { return "Hello"; } ----------------------------------------- Gather attributes from the function ----------------------------------------- function getAttributes(Reflector $reflection) { $attributes = $reflection->getAttributes(); $result = []; foreach ($attributes as $attribute) { $result[$attribute->getName()] = $attribute->getArguments(); } return $result; } $reflection = new ReflectionFunction("Hello"); print_r(getAttributes($reflection)); ----------------------------- OUTPUT ----------------------------- Array ( [ReadOnly] => Array ( ) [Property] => Array ( [type] => function [name] => Hello ) ) ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.246 (proxied: 202.142.74.148) ---- Manual Page -- http://php.net/manual/en/language.attributes.reflection.php Edit -- https://master.php.net/note/edit/125889 Del: integrated -- https://master.php.net/note/delete/125889/integrated Del: useless -- https://master.php.net/note/delete/125889/useless Del: bad code -- https://master.php.net/note/delete/125889/bad+code Del: spam -- https://master.php.net/note/delete/125889/spam Del: non-english -- https://master.php.net/note/delete/125889/non-english Del: in docs -- https://master.php.net/note/delete/125889/in+docs Del: other reasons-- https://master.php.net/note/delete/125889 Reject -- https://master.php.net/note/reject/125889 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#219269) next »