# __construct is like a normal method but without E_STRICT

- Thread: https://externals.io/message/69358
- Original archive: https://news-web.php.net/php.internals/69358
- Started by Robert Stoll on 2013-09-26T21:19:44+00:00
- Messages: 3
- 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

---

## #69358 — Robert Stoll — 2013-09-26T21:19:44+00:00

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

Heya

 

I would like to have some opinions on the topic  inconsistency between
methods and __construct

See the following code:

 

class A {

                function __construct($a) {}

                function foo($a) {}

}

class B extends A {

                function __construct($a, $b) {}

                function foo($a, $b) {}

}

 

If you work in strict mode, then you will see the error message

Strict Standards: Declaration of B::foo() should be compatible with
A::foo($a)

 

I perfectly understand that the strict standard cannot be applied to the
__construct and I would not suggest to change that. But I think it is
somewhat strange that I am able to call __construct as it was a normal
method from everywhere.

Am I the only one thinking this, is there actually someone who is using
__construct as re-initialising method?

 

Cheers,

Robert

---

## #69430 — Ferenc Kovacs — 2013-10-01T10:17:45+00:00

URL: https://externals.io/message/69358#69430 · In reply to: #69358

> Heya
>
>
>
> I would like to have some opinions on the topic  inconsistency between
> methods and __construct
>
> See the following code:
>
>
>
> class A {
>
>                 function __construct($a) {}
>
>                 function foo($a) {}
>
> }
>
> class B extends A {
>
>                 function __construct($a, $b) {}
>
>                 function foo($a, $b) {}
>
> }
>
>
>
> If you work in strict mode, then you will see the error message
>
> Strict Standards: Declaration of B::foo() should be compatible with
> A::foo($a)
>
>
>
> I perfectly understand that the strict standard cannot be applied to the
> __construct and I would not suggest to change that. But I think it is
> somewhat strange that I am able to call __construct as it was a normal
> method from everywhere.
>
> Am I the only one thinking this, is there actually someone who is using
> __construct as re-initialising method?
>
>
>
> Cheers,
>
> Robert
>
>
>
>
>
>
>
>
php doesn't invoke the parent's constructor from the subclass if the
subclass also have a constructor, so in that case calling
parent::__construct() manually is your only option if you want the parent
constructor to be executed.

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

---

## #69468 — Seva Lapsha — 2013-10-02T18:54:06+00:00

URL: https://externals.io/message/69358#69468 · In reply to: #69430

> > […]
> php doesn't invoke the parent's constructor from the subclass if the
> subclass also have a constructor, so in that case calling
> parent::__construct() manually is your only option if you want the parent
> constructor to be executed.
>

AFAIU, Robert talks about the external invocation, e.g.:

<?php $a = new Obj(); $a->__construct(); ?>

Regards,
Seva
