Re: php5 class initialization
| From: | Rasmus Lerdorf | Date: | Tue, 23 Mar 2004 18:11:12 +0000 |
| Subject: | Re: php5 class initialization | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-8689@lists.php.net to get a copy of this message | ||
On Tue, 23 Mar 2004, Brad Fisher wrote:
> Rasmus Lerdorf wrote:
>
> > I could see people doing:
> >
> > class foo {
> > function foo() {
> > ...constructor stuff...
> > }
> > function __construct() {
> > $this->foo();
> > }
> > }
>
> I actually prefer it the other way around... foo would call __construct in
> PHP4, and __construct would be called directly in PHP5 (with foo being
> ignored). As I understand the docs on php.net regading PHP5, the __construct
> method has precedence over foo as a constructor. I've also run into a case
> where a class worked fine in PHP4 and not in PHP5 because of a method
> existing with the same name as the class. It was seen as a constructor, and
> not a method, even though it is always called statically.
Sure, but George was asking for a case. I think the case where you have
some existing PHP4 code that you want to make minimal changes to but you
might have a little bit of PHP5-specific code to run in the constructor I
could see this sort of chaining being something people want. I am not
saying that is the way people should create a portable class, just that I
could see such code popping up. And the question was what to do about the
old-style constructor method. I think it would be very confusing if it
was some sort of illegal method name that wasn't callable.
-Rasmus