php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78248 ReflectionClass::getMethods() filters as ANY not ALL bitmap fields
Submitted: 2019-07-04 04:14 UTC Modified: 2019-07-04 08:11 UTC
From: zerkms at zerkms dot ru Assigned:
Status: Wont fix Package: Reflection related
PHP Version: 7.3.6 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: zerkms at zerkms dot ru
New email:
PHP Version: OS:

 

 [2019-07-04 04:14 UTC] zerkms at zerkms dot ru
Description:
------------
As always with bitmap filtering the items should be checked to satisfy all bitfields, not any of those

Test script:
---------------
<?php

class Foo
{
    public function one() {}
    
    static public function two() {}
    
    static protected function three() {}
}

$class = new ReflectionClass(Foo::class);

$methods = $class->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_PUBLIC);

foreach ($methods as $method) {
    var_dump($method);
}

Expected result:
----------------
object(ReflectionMethod)#3 (2) {
  ["name"]=>
  string(3) "two"
  ["class"]=>
  string(3) "Foo"
}

Actual result:
--------------
object(ReflectionMethod)#2 (2) {
  ["name"]=>
  string(3) "one"
  ["class"]=>
  string(3) "Foo"
}
object(ReflectionMethod)#3 (2) {
  ["name"]=>
  string(3) "two"
  ["class"]=>
  string(3) "Foo"
}
object(ReflectionMethod)#4 (2) {
  ["name"]=>
  string(5) "three"
  ["class"]=>
  string(3) "Foo"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-04 08:01 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2019-07-04 08:01 UTC] nikic@php.net
I'm not sure which behavior is "right" here (both are useful depending on context and the current one matches the semantics of the bitwise operation), but this is a long-standing documented behavior that cannot be changed.
 [2019-07-04 08:11 UTC] zerkms at zerkms dot ru
> and the current one matches the semantics of the bitwise operation

unless it's never the case: I'm not sure I ever seen bitmap filters that implement `ANY` semantics.

I can pass an integer value with no bitwise `|`, or can assemble the number using the bitwise `&`.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 19:01:26 2024 UTC