Re: PHP 4.0 Bug #2675 Updated: Misbehavior of object initializers

From: Date: Mon, 08 Nov 1999 04:42:35 +0000
Subject: Re: PHP 4.0 Bug #2675 Updated: Misbehavior of object initializers
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-12208@lists.php.net to get a copy of this message
At 03:41 PM 11/7/99 -0600, ZeroDiVide wrote:
You should use the Factory design pattern I suppose. How about the
following:
And then do something like (actually it doesn't even need to be $new_db = DB::Factory('mysql');
I had to check some references, but in java or other oop languages where the "factory" design pattern are used the object instaciator actually is completly overloading which is thecnically a "feature" of those languages vs c++.
So i guess the larger question here is are we doing java symantics or
c++ ?
PHP semantics :) I'm not sure what you can do in Java with constructors, but in this case, PHP is similar to C++. Is there a design paper or anything that shows where things are headed with the oop side of things?
Actually we never intended to make PHP a completely OOP language. We added some support to allow creation of self contained packages. We are not at this time heading in a completely OOP direction. Most PHP users still prefer to write simple procedural programs for their web sites than OO programs.
No it isn't. The point of overloading a constructor is to initialize the object ($this) with whatever default values you want. If you're doing inheritance and you need a new constructor for the offspring class, you might want to call the parent's constructor in addition to the added code of your new constructor. It's up to the developer to decide what exactly he wants to do. Right but wouldn't it be easy to have the function default to returning $this and if you don't want to or you want to polymorph into something else you'll return a different object reference or whatever you'd like.
No, because not all classes have constructors. Anyway, I really don't see a point of allowing this and it sounds pretty odd to me that some other languages do allow it. Also, there really is no problem with the code I sent you. Why not use that? Andi --- Andi Gutmans <andi@zend.com> http://www.zend.com/

« previous php.dev (#12208) next »