ZF-11405: View instance in view helper can be other than one it is currently called from.
Currently view inject itself into helpers only on helper instantiation. It is expected that helper contains current view object when called. It is true unless view object already instantiated helper and was cloned. In this case cloned view contains same helper instance as original view. And that helper contains original view if called from cloned view.
$this->setScriptPath('/some/path/to/view/scripts'); $this->partial('partial_in_path_specified_above.phtml'); //oops, wrong view here, as partial uses original view and we in cloned one
Example above involves partial helper, but this is most important with custom helpers. I can provide several use cases i had in mind if needed.
As workaround in my helpers with view dependency first parameter of direct() method is required instance if zend_view, so any call to this helpers looks like $this->fooHelper($this, ...); This ensures noone can forget to set view.
After some digging I think best way to fix this is to make sure view instance is current or inject it every time helper is called. As someone suggested, cloning helpers is a bad idea. We can't just set view on clone.
Ps: Actually I think internal array of helpers should be replaced with some sort of container or instance of helper broker so views can share helpers unless they told not to. It will introduce BC break though so it is completely out of scope here.