Return to Snippet

Revision: 50469
at August 23, 2011 23:13 by Roen


Initial Code
private function _property_exists_safe($class,$prop) {
        $r = property_exists($class, $prop);
        if (!$r) {
            $x = new ReflectionClass($class);
            $r = $x->hasProperty($prop);
        }
        return $r;
    }

Initial URL
http://php.net/manual/en/function.property-exists.php

Initial Description
Comes in handy for php magic functions such as __get and __set. This behaviour is fixed in php 5.3. Returns true also for private and protected properties using a reflectionclass

Initial Title
php property_exists fix for protected or private properties

Initial Tags
php

Initial Language
PHP