Pop-Up Thingie

>>> Magnum BBS <<<
  • Home
  • Forum
  • Files
  • Log in

  1. Forum
  2. Usenet
  3. COMP.LANG.PHP
  • ReflectionAttribute: IS_INSTANCEOF and getTarget()

    From alex@21:1/5 to All on Thu Oct 26 10:09:58 2023
    https://www.php.net/manual/en/reflectionattribute.gettarget.php

    https://www.php.net/manual/en/class.reflectionattribute.php#reflectionattribute.constants.is-instanceof

    what are they for?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J.O. Aho@21:1/5 to alex on Mon Nov 13 07:54:52 2023
    On 26/10/2023 10.09, alex wrote:

    Just my guesses as the documentation is a bit thin at the moment

    https://www.php.net/manual/en/reflectionattribute.gettarget.php

    There are a number of attributes you can give a class, TARGET_* and you
    will get the sum of all those targets as an unified bit value. 0 if none
    of the TARGET_* are set.


    https://www.php.net/manual/en/class.reflectionattribute.php#reflectionattribute.constants.is-instanceof

    this will give you something like typeof for the instance in question.

    --
    //Aho

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From alex@21:1/5 to All on Mon Nov 13 12:50:21 2023
    Il 13/11/23 07:54, J.O. Aho ha scritto:
    https://www.php.net/manual/en/reflectionattribute.gettarget.php

    There are a number of attributes you can give a class, TARGET_* and you
    will get the sum of all those targets as an unified bit value. 0 if none
    of the TARGET_* are set.

    mmmhhh...

    Are you sure?
    An example? (here's mine below)

    ~$ cat /tmp/aaa
    <?php

    #[ATTRIB]
    class TARGET_CLASS {

    #[ATTRIB]
    function TARGET_METHOD() {}

    }

    #[ATTRIB]
    function TARGET_FUNCTION() {}

    function TARGET_xxx() {}

    $reflections = [
    new ReflectionClass('TARGET_CLASS'),
    new ReflectionMethod('TARGET_CLASS::TARGET_METHOD'),
    new ReflectionFunction('TARGET_FUNCTION'),
    new ReflectionFunction('TARGET_xxx'),
    ];

    foreach ($reflections as $reflection) {
    echo $reflection->getName() . ': ';
    echo $reflection->getAttributes()[0]->getTarget() || "IS ZERO";
    echo PHP_EOL;
    }
    ~$ php /tmp/aaa
    TARGET_CLASS: 1
    TARGET_METHOD: 1
    TARGET_FUNCTION: 1
    TARGET_xxx: PHP Warning: Undefined array key 0 in /tmp/aaa on line 25
    PHP Fatal error: Uncaught Error: Call to a member function getTarget()
    on null in /tmp/aaa:25

    REPEAT:
    An example?

    https://www.php.net/manual/en/class.reflectionattribute.php#reflectionattribute.constants.is-instanceof

    this will give you something like typeof for the instance in question.

    typeof...???

    https://www.google.com/search?channel=fs&client=ubuntu-sn&q=php+typeof#ip=1

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From J.O. Aho@21:1/5 to alex on Mon Nov 13 14:32:39 2023
    On 13/11/2023 12.50, alex wrote:
    Il 13/11/23 07:54, J.O. Aho ha scritto:
    https://www.php.net/manual/en/reflectionattribute.gettarget.php

    There are a number of attributes you can give a class, TARGET_* and
    you will get the sum of all those targets as an unified bit value. 0
    if none of the TARGET_* are set.

    mmmhhh...

    Are you sure?

    No and yes, it wasn't really what I thought

    I thought it would give the value of #[Attribute(Attribute::TARGET_CLASS|Attribute::IS_REPEATABLE)] (65)

    but it only gives you

    Attribute::TARGET_CLASS (1)
    Attribute::TARGET_FUNCTION (2)
    Attribute::TARGET_METHOD (4)

    see: https://github.com/php/php-src/blob/cc2bf119519c8dd7d6afa2b63aa4ea8b014f205d/Zend/zend_attributes.h

    You can see at the unitest: https://github.com/php/php-src/blob/cc2bf119519c8dd7d6afa2b63aa4ea8b014f205d/Zend/tests/attributes/020_userland_attribute_validation.phpt


    https://www.php.net/manual/en/class.reflectionattribute.php#reflectionattribute.constants.is-instanceof

    this will give you something like typeof for the instance in question.

    typeof...???

    just ignore this part.. typeof used in other languages when you want to
    know what type something is of and I was hasty in my reply and guessed
    without really reading.

    --
    //Aho

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • Who's Online

  • Recent Visitors

    • Centurion
      Sun Jun 7 16:59:51 2026
      from Berea, Ohio via Telnet
    • Furryboy
      Sun Jun 7 13:40:29 2026
      from Romania, Galati via SSH
    • Krenn
      Sun Jun 7 10:02:33 2026
      from Sydney, Nsw via Telnet
    • Spearb0y
      Sun Jun 7 07:41:05 2026
      from Massachusetts via SSH
    • Krenn
      Sun Jun 7 03:07:26 2026
      from Sydney, Nsw via Telnet
    • Krenn
      Sun Jun 7 01:30:12 2026
      from Sydney, Nsw via Telnet
    • Centurion
      Sat Jun 6 23:27:30 2026
      from Berea, Ohio via Telnet
    • Ab Cadd
      Sat Jun 6 15:42:53 2026
      from Sheboygan, Wi via Telnet
  • System Info

    Sysop: Keyop
    Location: Huddersfield, West Yorkshire, UK
    Users: 715
    Nodes: 16 (2 / 14)
    Uptime: 01:51:22
    Calls: 12,098
    Calls today: 6
    Files: 15,003
    Messages: 6,517,868

© >>> Magnum BBS <<<, 2026