ZF-10263: Unable to use startMvc() in a subclass of Zend_Layout due to use of 'self' keyword

Issue Type: Bug Created: 2010-08-04T11:03:08.000+0000 Last Updated: 2012-03-14T00:24:01.000+0000 Status: Closed Fix version(s): - Next Major Release ()

Reporter: David (hndavid) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Layout

Related issues: Attachments:


Test case:

<pre class="highlight">

class MyLayout extends Zend_Layout

$layout = MyLayout::startMvc();

echo get_class($layout);

Expected output: MyLayout

Actual output: Zend_Layout

This is due to the use of the 'self' keyword in startMvc() which statically binds to the Zend_Layout class, irrespective of any subclasses. More info:

Here's a patch, but it only works on PHP 5.3+ due to the use of get_called_class().


Posted by David (hndavid) on 2010-08-04T11:06:41.000+0000

couldn't find how to attach a file

Posted by Matthew Weier O'Phinney (matthew) on 2010-08-04T11:39:02.000+0000

You can actually override the behavior within versions of PHP prior to 5.3; you just need to copy and paste the methods "getMvcInstance()" and "startMvc()" into your subclass. Once you have, however, all calls to either My_Layout::getMvcInstance() or Zend_Layout::getMvcInstance() will return a My_Layout object as long as you started the session using My_Layout.

I've blogged about this type of extension previously:…

In the meantime, we cannot make changes such as you suggest until 2.0, so I'm marking that as the fix version.

Posted by Matthew Weier O'Phinney (matthew) on 2010-08-04T11:39:23.000+0000

Scheduling for 2.0.

Posted by Adam Lundrigan (adamlundrigan) on 2012-03-14T00:24:01.000+0000

Will no be fixed in ZF1. No longer an issue with ZF2

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.