rick645 Posted November 10, 2023 Share Posted November 10, 2023 https://www.php.net/manual/en/reflectionattribute.gettarget.php Returns the target of the attribute as bitmask So what? Some examples? Cases of use? Quote Link to comment Share on other sites More sharing options...
requinix Posted November 11, 2023 Share Posted November 11, 2023 The targets are the Attribute::TARGET values.https://www.php.net/manual/en/language.attributes.classes.php Since an attribute can be applied to more than one type of thing, getTarget() returns the bitmask of those TARGETs. Then you can use normal bit arithmetic to find out if it applies to a class, or method, or whatever. Quote Link to comment Share on other sites More sharing options...
rick645 Posted November 13, 2023 Author Share Posted November 13, 2023 On 11/11/2023 at 7:22 PM, requinix said: The targets are the Attribute::TARGET values. ~$ php -r 'echo Attribute::TARGET;' PHP Fatal error: Uncaught Error: Undefined constant Attribute::TARGET in Command line code:1 Quote Link to comment Share on other sites More sharing options...
requinix Posted November 13, 2023 Share Posted November 13, 2023 https://www.php.net/manual/en/class.attribute.php Quote Link to comment Share on other sites More sharing options...
rick645 Posted November 14, 2023 Author Share Posted November 14, 2023 The page talks about Attribute::TARGET_*[1] and not Attribute::TARGET Anyway, do you know what the constant ReflectionAttribute::IS_INSTANCEOF is for? $ php -r 'echo ReflectionAttribute::IS_INSTANCEOF . PHP_EOL;' 2 So what? [1] Expandable in Attribute::TARGET_CLASS Attribute::TARGET_FUNCTION Attribute::TARGET_METHOD Attribute::TARGET_PROPERTY Attribute::TARGET_CLASS_CONSTANT Attribute::TARGET_PARAMETER Attribute::TARGET_ALL Attribute::IS_REPEATABLE Quote Link to comment Share on other sites More sharing options...
requinix Posted November 14, 2023 Share Posted November 14, 2023 5 hours ago, rick645 said: The page talks about Attribute::TARGET_*[1] and not Attribute::TARGET Yeah. "The targets are the Attribute::TARGET values." Plural. 5 hours ago, rick645 said: Anyway, do you know what the constant ReflectionAttribute::IS_INSTANCEOF is for? https://www.php.net/manual/en/class.reflectionattribute.php#reflectionattribute.constants.is-instanceof "Retrieve attributes using an instanceof check." Do you know how to "retrieve attributes"? Quote Link to comment Share on other sites More sharing options...
rick645 Posted November 14, 2023 Author Share Posted November 14, 2023 https://www.php.net/manual/en/language.attributes.reflection.php //... $attributes = $reflection->getAttributes(); //... Do you do this, or am I wrong? This is clear to me !!! But I don't understand what function performs the constant ReflectionAttribute::IS_INSTANCEOF Quote Link to comment Share on other sites More sharing options...
Solution kicken Posted November 14, 2023 Solution Share Posted November 14, 2023 Look at the documentation for getAttributes(). There is a flags parameter which is where you use the IS_INSTANCEOF constant. Quote The only other option available, is to use ReflectionAttribute::IS_INSTANCEOF, which will instead use instanceof for filtering. Quote Link to comment Share on other sites More sharing options...
rick645 Posted November 15, 2023 Author Share Posted November 15, 2023 t hanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.