php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71359 Coalescing operator on classes with overridden __get() method
Submitted: 2016-01-13 14:57 UTC Modified: 2016-06-15 07:19 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: kostasxx at gmail dot com Assigned: krakjoe
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.2 OS: Linux 4.1.13
Private report: No CVE-ID:
 [2016-01-13 14:57 UTC] kostasxx at gmail dot com
Description:
------------
The issue appears when using the new null coalescing operator on object parameters, when the defined class has override the magic __get() and an error is triggered inside it.

The script runs the __get() method and not the __isset(), so the error on __get() is triggered when the operator is used.

Test script:
---------------
http://www.pastebucket.com/97499

Expected result:
----------------
The expexted result should be not to trigger the error within the __get() method

GET
string(6) "value1"
GET
string(7) "default"

Actual result:
--------------
The error is triggered

GET
string(6) "value1"
GET
PHP Notice:  Property attribute2 does not exist in /var/www/html/test.php on line 23
PHP Stack trace:
PHP   1. {main}() /var/www/html/test.php:0
PHP   2. Coalescing->__get() /var/www/html/test.php:41
PHP   3. trigger_error() /var/www/html/test.php:23
/var/www/html/test.php:41:
string(7) "default"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-13 20:21 UTC] requinix@php.net
-Status: Open +Status: Verified
 [2016-01-13 20:21 UTC] requinix@php.net
https://3v4l.org/HBQRr

($x ?? $y) is defined as being equivalent to (isset($x) ? $x : $y) so __isset() should be getting called.
 [2016-03-20 17:39 UTC] nikic@php.net
The root cause for this is bug #50813.
 [2016-03-26 11:11 UTC] krakjoe@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2016-03-26 11:11 UTC] krakjoe@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2016-04-01 13:44 UTC] arjen at react dot com
This is only fixed in master, what about 7.0?

See https://bugs.php.net/bug.php?id=50813 and https://github.com/php/php-src/commit/373da7aa6f5e7bf57d434fd449f97770fb479d3e

Similar issue when using ?? and offsetSet/offsetExists and ArrayAccess (https://bugs.php.net/bug.php?id=71731) has been fixed in 7.0.
 [2016-04-01 14:51 UTC] krakjoe@php.net
It was merged into 7.0 too.
 [2016-04-04 08:05 UTC] arjen at react dot com
Then it's not in the NEWS file ;)
https://github.com/php/php-src/blob/PHP-7.0/NEWS
 [2016-04-04 08:23 UTC] krakjoe@php.net
My commits are bad, and I feel bad ... added ;)
 [2016-06-15 03:12 UTC] frej dot akki at gmail dot com
this bug has been resurfaced in 7.0.6/7
 [2016-06-15 05:40 UTC] krakjoe@php.net
I don't see it: https://3v4l.org/f0KrS
 [2016-06-15 07:05 UTC] kostasxx at gmail dot com
It isn't exactly the same error. The error appears when __isset() is not defined. Then, it executes first __get() before native isset().

See here: https://3v4l.org/RMS3W
 [2016-06-15 07:08 UTC] krakjoe@php.net
Open a new report please, someone will look at it.
 [2016-06-15 07:14 UTC] kostasxx at gmail dot com
I don't think it needs another issue. It's still the same, in different approach.
The first code example I used had, besides __get(), the __isset() method overridden. That part of the bug is, indeed, fixed.
The issue still occurs when the __isset() is not overridden. So, the bug that is related to __get() override still, partially, exists.

See here please: https://3v4l.org/RMS3W

Thanks :)
 [2016-06-15 07:19 UTC] krakjoe@php.net
It's a related, but different issue.
 [2016-06-15 07:21 UTC] kostasxx at gmail dot com
OK. I will create a new issue.

Thanks again
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Feb 21 18:01:40 2017 UTC