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

Description

Test case:


<?php

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: http://bugs.php.net/30934

Here's a patch, but it only works on PHP 5.3+ due to the use of get_called_class(). http://pastie.org/1075598

Comments

couldn't find how to attach a file

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: http://weierophinney.net/matthew/archives/…

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

Scheduling for 2.0.

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