Posted By

Roen on 08/23/11


php property-exists magic-functions private-property protected-property

Versions (?)

php property_exists fix for protected or private properties

 / Published in: PHP


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

  1. private function _property_exists_safe($class,$prop) {
  2. $r = property_exists($class, $prop);
  3. if (!$r) {
  4. $x = new ReflectionClass($class);
  5. $r = $x->hasProperty($prop);
  6. }
  7. return $r;
  8. }

Report this snippet  

You need to login to post a comment.