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