php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65044 Unable to filter using RelectionClass::getMethods
Submitted: 2013-06-16 10:09 UTC Modified: 2016-01-16 13:14 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: aik dot bold at gmail dot com Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.4.16 OS: Slackware 13 x64
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: aik dot bold at gmail dot com
New email:
PHP Version: OS:

 

 [2013-06-16 10:09 UTC] aik dot bold at gmail dot com
Description:
------------
I'm trying to get all public, but not static methods of a class using following 
code:

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

This however returns all public methods. It happens because of values of used 
constants:

ReflectionMethod::IS_PUBLIC - 256 (decimal) and 100000000 (binary)
ReflectionMethod::IS_STATIC - 1 (decimal) and 000000001 (binary)

This way binary subtraction doesn't really do a thing.

I suppose these constant values are designed to expand method range returned and 
not narrow down it instead.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-15 00:48 UTC] felipe@php.net
-Package: filter +Package: Reflection related
 [2016-01-16 13:14 UTC] danack@php.net
-Status: Open +Status: Not a bug
 [2016-01-16 13:14 UTC] danack@php.net
You have discovered that bit-flag operations do not behave the same as logic operations.

There no way to filter with the bit flags to just get the non-static methods. You will need to filter them yourself with !$reflectionMethod->isStatic() for all of the methods that match `$class->getMethods(ReflectionMethod::IS_PUBLIC)`
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 12 06:01:27 2024 UTC