Re: [PHP] Construction

2004-06-27 Thread David Goodlad
As far as I know, this is fairly common in most programming languages
(but I just woke up so don't take my word on it!).  It allows you a
lot greater control over the construction of your class, since you can
force the child class to override what the parent class's default
member variable values are by calling the parent constructor first, or
you can have it be overridden by the parent by calling the parent
constructor at the end of the child's constructor.

Dave

On Sat, 26 Jun 2004 20:51:58 -0700, Jason Davidson
[EMAIL PROTECTED] wrote:
 
 If you instantiate a child class, the parent class constructor is not
 called, is there a reason for this?  anyone know of plans to change
 this at all, 
 the obvious workaround is to call the parents constructor inside the
 childs constructor, but this seems kinda strange.
 
 Jason
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Construction

2004-06-27 Thread Paul Bissex
On Sat, 26 Jun 2004 20:51:58 -0700, Jason Davidson
[EMAIL PROTECTED] wrote:
 
 If you instantiate a child class, the parent class constructor is not
 called, is there a reason for this?  anyone know of plans to change
 this at all, 
 the obvious workaround is to call the parents constructor inside the
 childs constructor, but this seems kinda strange.

I think it's unlikely to change. PHP5 also works this way, though it
uses constructor methods named __construct (in addition to allowing
old-style constructors with the name of the class).

?php
// PHP5

class Foo
  {
  function __construct()
{
$this-x = data;
}
  }

class Bar extends Foo
  {
  function __construct()
{
parent::__construct();
$this-y = more data;
}
  }
?

FWIW Python also requires child classes to call parent constructors
manually. Not sure what the justification is for this design decision
is, though, in either language.  Anybody?

pb

-- 
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71W 42°19'42N

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Construction

2004-06-27 Thread Michael Sims
Paul Bissex wrote:
 FWIW Python also requires child classes to call parent constructors
 manually. Not sure what the justification is for this design decision
 is, though, in either language.  Anybody?

Flexibility, I would guess.  With PHP's current behavior one can:

(1) Call the parent constructor first, before the subclass constructor does
its work.
(2) Call the parent constructor last, after the subclass constructor does
its work.
(3) Call the parent constructor in the middle...doing some work before, and
then some work after. :)
(3) Pass through all of the subclass constructor's arguments to the parent
constructor unaltered.
(4) Change or filter some of the arguments that get passed to the parent
constuctor.
(5) Choose not to call the parent constructor at all.
(6) Many other things that I'm sure I'm overlooking...

If PHP called the parent constructor for you automagically, then how would
you implement the above options?  PHP would have to choose one approach and
stick to it.  I like the current behavior much better.

Forgive me if this has been mentioned in this thread previously, but PHP
does call the parent class constructor automatically if the subclass has no
constuctor, which does make sense

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Construction

2004-06-26 Thread Jason Davidson
If you instantiate a child class, the parent class constructor is not
called, is there a reason for this?  anyone know of plans to change
this at all, 
the obvious workaround is to call the parents constructor inside the
childs constructor, but this seems kinda strange.

Jason

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php