# Using grand-parent constructor

- Thread: https://externals.io/message/26286
- Original archive: https://news-web.php.net/php.internals/26286
- Started by Evert | Rooftop on 2006-10-31T20:12:45+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #26286 — Evert | Rooftop — 2006-10-31T20:12:45+00:00

URL: https://externals.io/message/26286#26286

Hi List,

Sorry if this is the wrong list for this kind of stuff.. I'd be happy to 
re-post this to the users mailing list.

With the recent updates that will raise `E_STRICT` on static calls that 
are non static, how do we properly do the following..

I have a class named 'GrandParent' a class named 'Parent' and a class 
named 'Child'

GrandParent has a constructor, Parent overrides it and Child does too.. 
What if I want to call GrandParent's constructor from the child?

Most languages allow this through casting the class into the ancestor 
and call then call the method, but I can't do this with PHP, or can I ? 
The other solution (right now) would be GrandParent::__construct(), but 
this is not OOP anymore.. So it seems kind of weird that we get limited 
in functionality, for OOP-ness, but not adding the functionality to 
solve common design problems that we're raised by introducing this..

Will we get casting in the future?

Evert

---

## #26287 — Jasper Bryant-Greene — 2006-10-31T20:25:16+00:00

URL: https://externals.io/message/26286#26287 · In reply to: #26286

adding parent::__construct() in the constructors of both Parent and
Child should do what you want.

Jasper

Evert | Rooftop wrote:
> Hi List,
> 
> Sorry if this is the wrong list for this kind of stuff.. I'd be happy to
> re-post this to the users mailing list.
> 
> With the recent updates that will raise `E_STRICT` on static calls that
> are non static, how do we properly do the following..
> 
> I have a class named 'GrandParent' a class named 'Parent' and a class
> named 'Child'
> 
> GrandParent has a constructor, Parent overrides it and Child does too..
> What if I want to call GrandParent's constructor from the child?
> 
> Most languages allow this through casting the class into the ancestor
> and call then call the method, but I can't do this with PHP, or can I ?
> The other solution (right now) would be GrandParent::__construct(), but
> this is not OOP anymore.. So it seems kind of weird that we get limited
> in functionality, for OOP-ness, but not adding the functionality to
> solve common design problems that we're raised by introducing this..
> 
> Will we get casting in the future?
> 
> Evert
> 

-- 
Jasper Bryant-Greene
Director
Album Limited

jasper@albumltd.co.nz
+64 21 708 334 / 0800 425 286
http://www.albumltd.co.nz/

---

## #26288 — Evert | Rooftop — 2006-10-31T20:39:46+00:00

URL: https://externals.io/message/26286#26288 · In reply to: #26287

Yes, but I want to ignore Parent behaviour, and Re-inherit GrandParent
behaviour..

Evert

Jasper Bryant-Greene wrote:
> adding parent::__construct() in the constructors of both Parent and
> Child should do what you want.
>
> Jasper
>
> Evert | Rooftop wrote:
>   
> > […]

---

## #26289 — Jochem Maas — 2006-10-31T20:41:00+00:00

URL: https://externals.io/message/26286#26289 · In reply to: #26287

Jasper Bryant-Greene wrote:
> adding parent::__construct() in the constructors of both Parent and
> Child should do what you want.

not only that but you 'should' _always_ really be calling the complete
constructor chain (e.g. Gparent < Parent < Child) according to "OO theory" -
the thought being that the construction phase is critical to instantiating
a class instance, a subclass should be able to rely on the fact that the baseclass
definition is completely/correct instantiated when it is created.

sounds to me that either your class hierarchy is 'wrong' or there is
some code in the Parent ctor that should belopng in some optional (protected?)
setup/utility function. just a thought.


> 
> Jasper
> 
> Evert | Rooftop wrote:
> > […]

---

## #26290 — Hannes Magnusson — 2006-10-31T21:45:51+00:00

URL: https://externals.io/message/26286#26290 · In reply to: #26288

GrandParent::__construct();


> Yes, but I want to ignore Parent behaviour, and Re-inherit GrandParent
> behaviour..
>
> Evert
>
> Jasper Bryant-Greene wrote:
> > […]
