note 128171 added to reflectionattribute.newinstance

From: Date: Mon, 30 Jan 2023 11:06:14 +0000
Subject: note 128171 added to reflectionattribute.newinstance
Groups: php.notes 
Request: Send a blank email to php-notes+get-220127@lists.php.net to get a copy of this message
Calling ReflectionAttribute::newInstance() using an attribute name that does not have a corresponding class will result in an error. Example : <?php #[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 : Attribute class "FakeAttribute" not found ---- 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/128171 Del: integrated -- https://main.php.net/note/delete/128171/integrated Del: useless -- https://main.php.net/note/delete/128171/useless Del: bad code -- https://main.php.net/note/delete/128171/bad+code Del: spam -- https://main.php.net/note/delete/128171/spam Del: non-english -- https://main.php.net/note/delete/128171/non-english Del: in docs -- https://main.php.net/note/delete/128171/in+docs Del: other reasons-- https://main.php.net/note/delete/128171 Reject -- https://main.php.net/note/reject/128171 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220127) next »