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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.