redefined constructor: old and new syntax

php.internals

Lorenzo Alberton

22 years ago
Why has this one been committed? http://cvs.php.net/diff.php/ZendEngine2/zend_compile.c?login=2&r1=1.551&r2=1.552 &ty=h It prevents constructors being redefined. That is fine, *except* for the following case: class MyClass { function MyClass() { //constructor for php4, //SHOULD be ignored by php5 } function __construct() { //constructor for php5, //ignored by php4 } } i.e. it doesn't allow a class to work on both php4 and php5. Or am I missing something obvious? Best regards, Lorenzo

Andi Gutmans

22 years ago
Well it doesn't really make sense to redefine a constructor. We added it on purpose. Do you want me to change it to E_STRICT? At 01:28 AM 3/18/2004 +0100, Lorenzo Alberton wrote:

Lorenzo Alberton

22 years ago
On Thu, 18 Mar 2004 09:10:42 +0200, Andi Gutmans wrote:
> Well it doesn't really make sense to redefine a constructor. We > added it on purpose. Do you want me to change it to E_STRICT?
if that is possible, yes, please. The example below should make it clear why redefinig a constructor *could* make sense. Thanks Lorenzo

Andi Gutmans

22 years ago
OK done At 09:21 AM 3/18/2004 +0100, Lorenzo Alberton wrote:

Stanislav Malyshev

22 years ago
Why would anyone need this? if __construct() contains php5-only syntax, it won't work anyway on php4. If it contains something that works in php4 - why do you need separate constructor? Anyway, since in no place besides constructor you can not do such tricks - why constructors should be the only place in the language where such tricks are used? What's so special in them? AG>> > >> class MyClass AG>> > >> { AG>> > >> function MyClass() { AG>> > >> //constructor for php4, AG>> > >> //SHOULD be ignored by php5 AG>> > >> } AG>> > >> AG>> > >> function __construct() { AG>> > >> //constructor for php5, AG>> > >> //ignored by php4 AG>> > >> } AG>> > >> } AG>> > >> AG>> > >> AG>> > >> i.e. it doesn't allow a class to work on both php4 and php5. Or AG>> > >> am I missing something obvious?
-- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/ +972-3-6139665 ext.109

Lorenzo Alberton

22 years ago
On Thu, 18 Mar 2004 10:59:40 +0200 (IST), Stanislav Malyshev wrote:
> Why would anyone need this? if __construct() contains php5-only > syntax, it won't work anyway on php4.
I just image the case of a class with some optimizations for php5, but with a fallback implementation of some of its features for php4 too, which get triggered by the constructor. Anyway, I agree this is a weak argument, there may be other ways to do the same thing.
> If it contains something that works in php4 > - why do you need separate constructor?
if the php4-way of naming a constructor is not going to be deprecated, then I don't. This is my main worry.
-- Lorenzo