Jump to content

What is it for ReflectionAttribute::IS_INSTANCEOF


Go to solution Solved by kicken,

Recommended Posts

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.

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

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"?

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

 

 

  • Solution

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.