ZF-7227: Zend_Reflection_Parameter::getType() method doesn't work properly
Description
Looking to following block code:
class Foo {
/**
* @param integer $a
* @param boolean $b
* @return boolean
*/
public function bar($a, $b) {
$r = new Zend_Reflection_Class($this);
$p = $r->getMethod('bar')->getParameters();
$t = $p[0]->getType();
//...
}
}
,the value of $t is null instead of integer. The problem seems to be on 111 and 112 lines, from Reflection/Parameter.php file ;value of "$this->getPosition()" should not decrement:
--- Parameter.php 2009-07-08 15:51:53.000000000 +0300
+++ ParameterFix.php 2009-07-08 17:34:50.000000000 +0300
@@ -108,8 +108,8 @@
if ($docblock = $this->getDeclaringFunction()->getDocblock()) {
$params = $docblock->getTags('param');
- if (isset($params[$this->getPosition() - 1])) {
- return $params[$this->getPosition() - 1]->getType();
+ if (isset($params[$this->getPosition()])) {
+ return $params[$this->getPosition()]->getType();
}
}
Comments
Posted by Alexander Chirkov (shurik239) on 2009-07-20T06:28:54.000+0000
i confirm this bag also
Posted by Ralph Schindler (ralph) on 2009-08-18T10:55:15.000+0000
Changing to "Trivial" priority. "Should Have" in "Next Mini Release". Assigning to user [~carlton]
Posted by Carlton Gibson (carlton) on 2009-08-21T07:19:47.000+0000
Changes to tests/ and library/
Posted by Carlton Gibson (carlton) on 2009-09-11T02:50:07.000+0000
Should be fixed by revision 18073. (Please Review.)
Posted by Carlton Gibson (carlton) on 2009-09-17T05:25:20.000+0000
Merged to release branch in r18161
Posted by Benjamin Eberlei (beberlei) on 2009-09-18T07:10:57.000+0000
This bugfix breaks Zend_CodeGenerator testsuite, now generating code with primative types in the parameter hints
Posted by Carlton Gibson (carlton) on 2009-09-18T09:55:41.000+0000
Benjamin, this is... er... interesting.
The bug fix looks correct to me: the old test case was passing by luck -- it just happened that two params had the same type and so the fact the type for the wrong parameter was being returned wasn't picked up.
The new test case goes through each of the parameters and so picks up the error (it's not just THAT the old code fails, but HOW it fails that is interesting.) With the bug fix in place the new test passes. I've also been using it heavily and have not NOTICED a problem.
Of course there could be something else going on... :-)
I've not time to pop into the BugHunt today but I'm totally happy to track this one down. (It just so happens I wanted to get into Zend_CodeGenerator anyway.) Which tests were passing at r18072 but fail at r18073? (If you like, you can create a case and assign it to me -- or reopen this one if you think there is a fault with the fix -- sorry I can't help sooner!)
Posted by Benjamin Eberlei (beberlei) on 2009-09-19T14:09:00.000+0000
Hey Carlton,
CodeGenerator is the problem, it dependent on this bug ;-) I fixed it already so no problem! :-)