php property_exists fix for protected or private properties

/ Published in: PHP
Save to your folder(s)

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

Copy this code and paste it in your HTML
  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


RSS Icon Subscribe to comments

You need to login to post a comment.