Bug #75831 [NEW]: Coalesce operator ?? never uses the default isset() handler
| From: | nobots dot nospam at example dot org | Date: | Wed, 17 Jan 2018 11:44:23 +0000 |
| Subject: | Bug #75831 [NEW]: Coalesce operator ?? never uses the default isset() handler | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-213581@lists.php.net to get a copy of this message | ||
From: nobots dot nospam at example dot org
Operating system:
PHP version: 7.2.1
Package: *General Issues
Bug Type: Bug
Bug description:Coalesce operator ?? never uses the default isset() handler
Description:
------------
The coalesce operator calls __get(prop) directly without testing
isset($obj->prop) first.
It only calls isset($obj->prop) if there is an explicit user-defined
__isset() handler.
Test script:
---------------
class Bar{
function __get($a){
throw new Error("no prop error\n");
}
}
$bar = new Bar;
try{
var_dump($bar->foo ?? "qux"); // error...
} catch(Throwable $e){ echo $e->getMessage(); }
var_dump(isset($bar->foo)); // ...but this works fine
Expected result:
----------------
class Bar{
function __isset($a){
return isset($this->{$a});
// I shouldn't be forced to implement this,
// since it looks exactly like the default isset() handler
}
function __get($a){
throw new Error("no prop error\n");
}
}
$bar = new Bar;
var_dump($bar->foo ?? "qux"); // works now, without errors...
--
Edit bug report at https://bugs.php.net/bug.php?id=75831&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75831&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75831&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75831&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75831&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75831&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75831&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75831&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75831&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75831&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75831&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75831&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75831&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75831&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75831&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75831&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75831&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75831&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75831&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75831&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75831&r=mysqlcfg