Johannes Schlueter wrote:
Hi Greg,

Greg Beaver wrote:


Try this code (which worked in 5.0.3)

<?php
class a { public function __construct(){}}
class b extends a { protected function __construct(){}}
?>


This was changed since such a change of visibility makes no sense - if you
extend a class it should still be compatible with it's parent class.

I highly recommend removing this restriction for constructors. The programmer should be the one to determine whether this makes sense. For other methods that are not instance-dependent, this restriction makes perfect sense. most methods can be called by any instance without needing to know what the class is. constructors are not like this. They are tightly bound to the specific class they are in. The same reasoning was used to remove the restrictions on constructor arguments - constructors are not normal methods.


I am extending a general purpose XML_RPC server implementation which is designed to be instance based, and making it a singleton. There is nothing wrong with this, and object instances are still 100% compatible.

Nobody in their right mind expects to be able to instantiate a child class without knowing anything about it - each class does something unique and possibly incompatible with the base class, otherwise there would be no point in extending the base class.

This seems a case of PHP trying to prevent me from doing logic errors without knowing anything about the code, i.e. not in the PHP spirit.

Greg

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to