php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76773 Traits used on the parent are ignored for child classes
Submitted: 2018-08-21 12:43 UTC Modified: 2018-08-23 11:14 UTC
From: nicolas dot grekas+php at gmail dot com Assigned: daverandom (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.3.0beta2 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nicolas dot grekas+php at gmail dot com
New email:
PHP Version: OS:

 

 [2018-08-21 12:43 UTC] nicolas dot grekas+php at gmail dot com
Description:
------------
See test script or https://3v4l.org/BKhG3

Test script:
---------------
<?php

trait MyTrait
{
    public function hello()
    {
        echo __CLASS__, "\n";

        if (\is_callable(array('parent', __FUNCTION__))) {
            parent::hello();
        }
    }
}

class ParentClass
{
    use MyTrait;
}

class ChildClass extends ParentClass
{
    use MyTrait;
}

$c = new ChildClass();
$c->hello();

Expected result:
----------------
ChildClass
ParentClass

(as is the case since 5.4)

Actual result:
--------------
ParentClass

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-21 16:49 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: pmmaga
 [2018-08-21 16:49 UTC] cmb@php.net
This regression has apparently been introduced by commit
179ed6e[1].  Pedro, could you please have a look at this issue?

[1] <http://git.php.net/?p=php-src.git;a=commit;h=179ed6e>
 [2018-08-21 18:44 UTC] pmmaga@php.net
-Assigned To: pmmaga +Assigned To: daverandom
 [2018-08-21 18:44 UTC] pmmaga@php.net
Indeed, that is the cause. daverandom already came up with a fix in https://github.com/php/php-src/pull/3454 thus I'm assigning it to him. Thanks cmb for the heads up and thanks Nicolas for the report.
 [2018-08-22 12:09 UTC] cmb@php.net
Automatic comment on behalf of daverandom
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9ace33b9c5d06b869b2aec577b119b0494840931
Log: Fix #76773 - Methods with a concrete scope need to be added again
 [2018-08-22 12:09 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2018-08-23 10:53 UTC] nicolas dot grekas+php at gmail dot com
I don't know if this is related, but today the engine cannot load any traits, see
https://travis-ci.org/nicolas-grekas/symfony/builds/419595016
 [2018-08-23 11:06 UTC] daverandom@php.net
I think it's more likely to be related to https://github.com/php/php-src/commit/67397970b25d03254f000c36a73204720475b324, please report a new bug
 [2018-08-23 11:14 UTC] nicolas dot grekas+php at gmail dot com
Filled https://bugs.php.net/76783
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 08:01:28 2024 UTC