|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-01-07 14:56 UTC] danack@php.net
[2019-01-07 16:26 UTC] tom at inflatablecookie dot com
[2019-01-07 22:52 UTC] cmb@php.net
-Status: Open
+Status: Duplicate
-Assigned To:
+Assigned To: cmb
[2019-01-07 22:52 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 00:00:01 2025 UTC |
Description: ------------ This is a -very- odd one.. Inheriting a __construct method from a trait in an implementing class does not work correctly if the fully qualified name of the class is of a certain combination of namespace and classname length - apparently 11 characters total. When applied, if the class is inspected via Reflection, the __construct method appears in the method list, however it is not considered a constructor by isConstructor(), and is not called on object instantiation. Disabling OpCache does not appear to have any effect on the issue. I'm running the stock homebrew packaged version of PHP 7.3.0 on Mac OS Mojave - a few PECL extensions have been added to the installation, though disabling all of them makes no difference to the issue. Test script: --------------- <?php namespace ab\abc { class Abc { use test; } class Abcd { use test; } trait test { public function __construct() { echo '__construct '.get_class($this)."\n"; } } new Abc(); new Abcd(); } Expected result: ---------------- Console output should be: > __construct ab\abc\Abc > __construct ab\abc\Abcd Actual result: -------------- > __construct ab\abc\Abc Only the first line is echoed, the constructor for Abcd is never called (order of instantiation of the two classes is irrelevant). Changing the namespace to "abc\abcd" for example however fixes the issue and both lines are echoed. The name of the trait does not appear to have any effect. The characters used in namespace or classname do not matter, only the combined length.