-
Notifications
You must be signed in to change notification settings - Fork 89
Undefined $factory
notice fix
#269
Undefined $factory
notice fix
#269
Conversation
60d2409
to
cf703e8
Compare
@@ -355,6 +355,8 @@ protected function createServiceViaCallback($callable, $cName, $rName) | |||
} elseif (is_array($callable)) { | |||
// reset both rewinds and returns the value of the first array element | |||
$factory = reset($callable); | |||
} else { | |||
$factory = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't it be initialized as null
first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, just a question of style preference. I did it this way to avoid an unnecessary double-assignment, but if you prefer to trim a couple of lines by eliminating the else clause, that works fine too. I'll change it if you wish.
test/TestAsset/FooStaticFactory.php
Outdated
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2018
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks -- fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
Thanks @demiankatz! Released in |
When a plugin manager uses a static class method as a factory (i.e.
FactoryClass::factoryMethod
), as of release 2.7.10, it causes an undefined variable notice to be thrown due to an uncovered else case. This pull request provides a test case to demonstrate the problem as well as a fix. This problem does not appear to exist in the 3.x code, so it is presumably a side effect of backporting to 2.7. However, for projects depending on earlier versions of the service manager, it can be a significant problem and should be corrected -- that is why I am targeting this PR against the release-2.7 branch.