ZF-2801: Constructor of Zend_Controller_Front should be protected to allow extending the front controller


The constructor is currently private, but to extend the Front controller it would be helpful to have it protected.


You can override any method of a parent class, as long as you set the visibility equal to or less restrictive than the visibility in the parent class. In the case of a singleton such as Zend_Controller_Front, you'll also need to extend getInstance() to ensure that the current class is the one instantiated.

I've blogged on this previously:…

But: in PHP 5.3 the behaviour has been changed slightly. If the parent constructor is private it can't be called from the extending class. The following example works in 5.2 but no longer in 5.3: {{{ <?php class Parent2 { public static function getInstance() { return new self(); }

private function __construct()


class Child extends Parent2 { public static function getInstance() { return new self(); } }

var_dump(Child::getInstance()); }}}

PHP 5.3 does not have a stable API at this point, and this new behavior could still change. Once the 5.3 API stabilizes, we can revisit this issue.

The point is, calling a private constructor from a descending class is just wrong and will never work. Private properties and methods are only visible to the declaring class. Allowing to call private properties of a class from static methods was a bug and extending Zend_Controller_Front therefore just worked because of this inconsistency in the object model of PHP.

Shouldn't we leave it open or mark it as LATER or something?

Scheduling for 1.5.1 release.

Visibility changed in trunk and 1.5 release branch