Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reflection properties Filter

Tags:

php

I have a class with public, public static, private and private static properties and i'm trying to get only the public ones. I just can't get the filter right for some reason, i tried

ReflectionProperty::IS_PUBLIC & ~ReflectionProperty::IS_STATIC

or

ReflectionProperty::IS_PUBLIC & (ReflectionProperty::IS_PUBLIC | ~ReflectionProperty::IS_STATIC)

among other things but either i keep getting the static public or the private static ones.

like image 242
francis Avatar asked Oct 04 '22 12:10

francis


1 Answers

You would need to query all publics and then filter the public statics out like this:

$ro = new ReflectionObject($obj);

$publics = array_filter(
    $ro->getProperties(ReflectionProperty::IS_PUBLIC), 
    function(ReflectionProperty $prop) {
        return !$prop->isStatic();
    }
);
like image 162
Ja͢ck Avatar answered Oct 10 '22 11:10

Ja͢ck