Skip to content

Commit

Permalink
ObjectMixin: magic @methods are created only when corresponding prope…
Browse files Browse the repository at this point in the history
…rty exists [Closes #1230][Closes #1344]
  • Loading branch information
dg committed Jan 11, 2014
1 parent 22a5320 commit 9374161
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
7 changes: 1 addition & 6 deletions Nette/common/ObjectMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ public static function call($_this, $name, $args)

} elseif (isset($methods[$name]) && is_array($methods[$name])) { // magic @methods
list($op, $rp, $type) = $methods[$name];
if (!$rp) {
throw new MemberAccessException("Magic method $class::$name() has not corresponding property $$op.");

} elseif (count($args) !== ($op === 'get' ? 0 : 1)) {
if (count($args) !== ($op === 'get' ? 0 : 1)) {
throw new InvalidArgumentException("$class::$name() expects " . ($op === 'get' ? 'no' : '1') . ' argument, ' . count($args) . ' given.');

} elseif ($type && $args && !self::checkType($args[0], $type)) {
Expand Down Expand Up @@ -286,8 +283,6 @@ public static function getMagicMethods($class)
$type = $rc->getNamespaceName() . '\\' . $type;
}
$methods[$name] = array($op, $rp, $type);
} else {
$methods[$name] = array($prop, NULL, NULL);
}
}
return $methods;
Expand Down
4 changes: 2 additions & 2 deletions tests/Nette/common/Object.magicMethod.inheritance.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ Assert::same( 'hello', $obj->getA() );

Assert::exception(function() use ($obj) {
$obj->setC(123);
}, 'Nette\MemberAccessException', 'Magic method ChildClass::setC() has not corresponding property $c.');
}, 'Nette\MemberAccessException', 'Call to undefined method ChildClass::setC().');


Assert::exception(function() use ($obj) {
$obj->setB(123);
}, 'Nette\MemberAccessException', 'Magic method ChildClass::setB() has not corresponding property $b.');
}, 'Nette\MemberAccessException', 'Call to undefined method ChildClass::setB().');

0 comments on commit 9374161

Please sign in to comment.