Re: __construct is like a normal method but without E_STRICT
| From: | Ferenc Kovacs | Date: | Tue, 01 Oct 2013 10:17:45 +0000 |
| Subject: | Re: __construct is like a normal method but without E_STRICT | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-69430@lists.php.net to get a copy of this message | ||
On Thu, Sep 26, 2013 at 11:19 PM, Robert Stoll <rstoll@tutteli.ch> wrote:
> 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