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

Issue Type: Improvement Created: 2008-03-04T07:36:13.000+0000 Last Updated: 2008-03-21T18:52:02.000+0000 Status: Resolved Fix version(s): - 1.5.1 (25/Mar/08)

Reporter: Lars Strojny (lars) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Controller

Related issues: Attachments: - 005-Zend_Controller_Front-protected-constructor.diff


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


Posted by Matthew Weier O'Phinney (matthew) on 2008-03-04T07:51:55.000+0000

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:…

Posted by Lars Strojny (lars) on 2008-03-04T08:21:16.000+0000

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()); }

Posted by Matthew Weier O'Phinney (matthew) on 2008-03-04T08:50:17.000+0000

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.

Posted by Lars Strojny (lars) on 2008-03-04T09:31:37.000+0000

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.

Posted by Lars Strojny (lars) on 2008-03-11T03:28:21.000+0000

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

Posted by Matthew Weier O'Phinney (matthew) on 2008-03-17T13:27:50.000+0000

Scheduling for 1.5.1 release.

Posted by Matthew Weier O'Phinney (matthew) on 2008-03-21T15:31:48.000+0000

Visibility changed in trunk and 1.5 release branch

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.