Skip to content
This repository has been archived by the owner on Apr 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #145 from mrosoiu/nonexisting-meth
Browse files Browse the repository at this point in the history
Fix stacktrace scope when calling an undefined method using call_user_func_array().
  • Loading branch information
thekid committed Apr 10, 2012
2 parents e7029b8 + b61d9d1 commit db74904
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/src/main/php/lang/Object.class.php
Expand Up @@ -94,11 +94,18 @@ public function __call($name, $args) {
return call_user_func_array(array($this, substr($name, 1)), $args);
}
$t= debug_backtrace();

// Get self
$i= 1; $s= sizeof($t);
while (!isset($t[$i]['class']) && $i++ < $s) { }
$self= $t[$i]['class'];
$scope= $t[$i+ 1]['class'];
if (isset(xp::$registry['ext'][$scope])) {

// Get scope
$i++;
while (!isset($t[$i]['class']) && $i++ < $s) { }
$scope= isset($t[$i]['class']) ? $t[$i]['class'] : NULL;

if (NULL != $scope && isset(xp::$registry['ext'][$scope])) {
foreach (xp::$registry['ext'][$scope] as $type => $class) {
if (!$this instanceof $type || !method_exists($class, $name)) continue;
array_unshift($args, $this);
Expand Down
Expand Up @@ -139,5 +139,25 @@ public function toStringMethod() {
$o->toString()
);
}

/**
* Tests call to undefined method
*
* @see xp://lang.Object#__call
*/
#[@test, @expect(class= 'lang.Error', withMessage= '/Call to undefined method .+::undefMethod\(\) from scope net\.xp_framework\.unittest\.core\.ObjectTest/')]
public function callUndefinedMethod() {
create(new Object())->undefMethod();
}

/**
* Tests call to undefined method using call_user_func_array()
*
* @see xp://lang.Object#__call
*/
#[@test, @expect(class= 'lang.Error', withMessage= '/Call to undefined method .+::undefMethod\(\) from scope net\.xp_framework\.unittest\.core\.ObjectTest/')]
public function callUndefinedMethod_call_user_func_array() {
call_user_func_array(array(new Object(), 'undefMethod'), array());
}
}
?>

0 comments on commit db74904

Please sign in to comment.