Re: Using a Resource as a Class Property



Michael Fesser wrote:

Quite simple: A base class with a member variable and a method that
performs some action with that. Since this is done in the constructor,
every child class has to be able to initialize the data before calling
the parent constructor, as you can see in B::__construct(). If PHP would
automatically call the parent constructor, this would be impossible.

So extended (child?) classes MUST NOT (for OOP reasons) automatically call a constructor. Rather, it should be called manually, if and when it's desired.

And this is not unique to PHP.

Zat right?

(Scuse me if I'm being dense, but I got some head stuff going on.)
.



Relevant Pages

  • Re: What does the CLR do when you instantiate an object? - Continue
    ... process right at the beginning of the ChildClass constructor. ... built before the parent constructor is called. ... exists and it is created before the object of the child class instantiation ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Using a Resource as a Class Property
    ... automatically call the parent constructor, ... class constructor automatically before any code is executed in the child class constructor. ... PHP doesn't automatically call constructors BUT doing so would be more in keeping with the Tao of OOP. ... I seriously considered writing the classes in a way to where the parent would *presume* all kinds of stuff about the child, but it didn't jibe with my obsession with atomicity - so I didn't do it. ...
    (comp.lang.php)
  • Re: Using a Resource as a Class Property
    ... But as soon as your child class uses its own ... constructor, you have to manually call the parent one. ... Is that a normal OOP way to do it - done that way in C++ and whatnot - or is this unique to PHP? ...
    (comp.lang.php)
  • Re: Using a Resource as a Class Property
    ... PHP doesn't do that automatically, except if the child class ... constructor, you have to manually call the parent one. ... public function __construct{ ...
    (comp.lang.php)
  • Re: Using a Resource as a Class Property
    ... Sanders Kaufman wrote: ... every child class has to be able to initialize the data before calling ... automatically call the parent constructor, ...
    (comp.lang.php)