Bug #77291 [Opn->Ana]: __isset() magic method doesn't work if implemented via a trait.
| From: | cmb@php.net | Date: | Fri, 14 Dec 2018 19:13:55 +0000 |
| Subject: | Bug #77291 [Opn->Ana]: __isset() magic method doesn't work if implemented via a trait. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218455@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77291&edit=1
ID: 77291
Updated by: cmb@php.net
Reported by: tandrewbennett at hotmail dot com
Summary: __isset() magic method doesn't work if implemented
via a trait.
-Status: Open
+Status: Analyzed
Type: Bug
Package: *General Issues
Operating System: Ubuntu 16.04
PHP Version: 7.3.0
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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>.
Previous Comments:
------------------------------------------------------------------------
[2018-12-14 00:34:47] 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-13 23:32:30] 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-13 09:31:04] 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 07:10:11] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77291&edit=1