Bug #77470 [Opn->Ver]: Methods in traits can unwillingly function as constructor
| From: | nikic@php.net | Date: | Wed, 16 Jan 2019 15:52:21 +0000 |
| Subject: | Bug #77470 [Opn->Ver]: Methods in traits can unwillingly function as constructor | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219008@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77470&edit=1
ID: 77470
Updated by: nikic@php.net
Reported by: bas at dmt-software dot nl
Summary: Methods in traits can unwillingly function as
constructor
-Status: Open
+Status: Verified
Type: Bug
Package: Class/Object related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
I agree that we should only treat __construct as a constructor when coming from a trait.
Interesting that this only comes up now, probably not many people using traits with non-namespaced
code.
Previous Comments:
------------------------------------------------------------------------
[2019-01-16 15:44:01] bas at dmt-software dot nl
Description:
------------
A class without __construct method cannot use a trait that has a method that equals the class
it's name. It will execute the trait method as constructor when E_DEPRECATED errors are
ignored. This should never happen.
Test script:
---------------
error_reporting(E_ALL ^ E_DEPRECATED);
class Callback {
use CallbackTrait;
}
trait CallbackTrait {
public function callback() {
echo 'this is called';
}
}
new Callback();
---
https://3v4l.org/CWBai
Expected result:
----------------
It should ignore the method as constructor like extends does or it should trigger a fatal error as
it does when a constructor is present (https://3v4l.org/nbh6X)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77470&edit=1