php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77291 magic methods inherited from a trait may be ignored
Submitted: 2018-12-13 07:10 UTC Modified: 2019-01-07 22:53 UTC
From: tandrewbennett at hotmail dot com Assigned: cmb (profile)
Status: Closed Package: *General Issues
PHP Version: 7.3.0 OS: Ubuntu 16.04
Private report: No CVE-ID: None
 [2018-12-13 07:10 UTC] tandrewbennett at hotmail dot com
Description:
------------
The __isset() magic method is no longer invoked on a class if implemented via a Trait.

Test script:
---------------
trait AccessibleProperties
{
    public function __isset($property)
    {
        return property_exists($this, $property);
    }

    public function __get($property)
    {
        if (property_exists($this, $property)) {
            return $this->$property;
        }
    }
}

class Foo {
    use AccessibleProperties;

    protected $a = 'Some value';
}

$foo = new Foo;
$foo->a;        // this works: returns 'Some value'
isset($foo->a); // this doesn't work: returns false





Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-13 09:31 UTC] danack@php.net
-Status: Open +Status: Feedback
 [2018-12-13 09:31 UTC] danack@php.net
This appears to work for me on PHP 7.3.0 https://3v4l.org/i9Lpv

Please can you try with OPCache disabled, and/or disabling any non-core extensions you have enabled?
 [2018-12-13 23:32 UTC] tandrewbennett at hotmail dot com
-Status: Feedback +Status: Open
 [2018-12-13 23:32 UTC] tandrewbennett at hotmail dot com
So this seems to go beyond the scope of what I originally thought. I think this is somehow related to autoloading (but I'm not quite sure). I've created a sample app to reproduce the error:

git clone git@github.com:tabennett/php-7.3.0-error.git
CD into the app
composer install
vendor/bin/phpunit

If you rename Foo to a class that has two words (e.g FooBar) this error goes away! Alternatively, if you set the PSR-4 namespace in composer.json to something with two words it also goes away.
 [2018-12-14 00:34 UTC] tandrewbennett at hotmail dot com
Also, here is an updated version from 3v4l.org (wrapping in namespaces triggers the error) if you don't want to clone down the demo repo I created.
https://3v4l.org/rSfeG
 [2018-12-14 19:13 UTC] cmb@php.net
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: cmb
 [2018-12-14 19:13 UTC] cmb@php.net
Thanks for reporting this issue, and for providing a simple
reproducer!

This regression has been introduced with commit 43aca31[1].  It is
not particularly related to namespaces, and does not only affect
__isset(), but rather all magic methods which are inherited from a
trait, whose name has the same length as the class name, see, for
instance, <https://3v4l.org/0jmp1>.
 [2018-12-14 19:30 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #77291: magic methods inherited from a trait may be ignored
On GitHub:  https://github.com/php/php-src/pull/3707
Patch:      https://github.com/php/php-src/pull/3707.patch
 [2018-12-16 12:43 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0061db5503497458a85c40fb6bf1e2da80e7a036
Log: Fix #77291: magic methods inherited from a trait may be ignored
 [2018-12-16 12:43 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2019-01-07 22:53 UTC] cmb@php.net
-Summary: __isset() magic method doesn't work if implemented via a trait. +Summary: magic methods inherited from a trait may be ignored
 [2019-01-07 22:53 UTC] cmb@php.net
To clarify: the length of the class name is supposed to mean the
resolved class name as would be provided by the magic ::class
constant.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC