Nette\Utils\ObjectMixin::hasProperty PHP Method

hasProperty() public static method

Checks if the public non-static property exists.
public static hasProperty ( $class, $name ) : boolean | 'event'
return boolean | 'event'
    public static function hasProperty($class, $name)
    {
        static $cache;
        $prop =& $cache[$class][$name];
        if ($prop === NULL) {
            $prop = FALSE;
            try {
                $rp = new \ReflectionProperty($class, $name);
                if ($rp->isPublic() && !$rp->isStatic()) {
                    $prop = $name >= 'onA' && $name < 'on_' ? 'event' : TRUE;
                }
            } catch (\ReflectionException $e) {
            }
        }
        return $prop;
    }

Usage Example

Example #1
0
 /**
  * @return void
  * @throws MemberAccessException
  */
 public function __unset($name)
 {
     $class = get_class($this);
     if (!ObjectMixin::hasProperty($class, $name)) {
         throw new MemberAccessException("Cannot unset the property {$class}::\${$name}.");
     }
 }