本文整理汇总了PHP中Nette\Utils\ObjectMixin::strictGet方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectMixin::strictGet方法的具体用法?PHP ObjectMixin::strictGet怎么用?PHP ObjectMixin::strictGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\ObjectMixin
的用法示例。
在下文中一共展示了ObjectMixin::strictGet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ucfirst
/**
* @return mixed property value
* @throws MemberAccessException if the property is not defined.
*/
public function &__get($name)
{
$class = get_class($this);
$uname = ucfirst($name);
if ($prop = ObjectMixin::getMagicProperty($class, $name)) {
// property getter
if (!($prop & 0b1)) {
throw new MemberAccessException("Cannot read a write-only property {$class}::\${$name}.");
}
$m = ($prop & 0b10 ? 'get' : 'is') . $uname;
if ($prop & 0b100) {
// return by reference
return $this->{$m}();
} else {
$val = $this->{$m}();
return $val;
}
} elseif ($name === '') {
throw new MemberAccessException("Cannot read a class '{$class}' property without name.");
} elseif (($methods =& ObjectMixin::getMethods($class)) && isset($methods[$m = 'get' . $uname]) || isset($methods[$m = 'is' . $uname])) {
// old property getter
trigger_error("Add annotation @property for {$class}::\${$name} or use {$m}()" . ObjectMixin::getSource(), E_USER_DEPRECATED);
if ($methods[$m] === 0) {
$methods[$m] = (new \ReflectionMethod($class, $m))->returnsReference();
}
if ($methods[$m] === TRUE) {
return $this->{$m}();
} else {
$val = $this->{$m}();
return $val;
}
} elseif (isset($methods[$name])) {
// public method as closure getter
trigger_error("Accessing methods as properties via \$obj->{$name} is deprecated" . ObjectMixin::getSource(), E_USER_DEPRECATED);
$val = Callback::closure($this, $name);
return $val;
} elseif (isset($methods['set' . $uname])) {
// property getter
throw new MemberAccessException("Cannot read a write-only property {$class}::\${$name}.");
} else {
ObjectMixin::strictGet($class, $name);
}
}