Bug #72408 [Fbk->Opn]: Coalescing operator on classes with overridden __get() method and NOT __isset()

From: Date: Wed, 15 Jun 2016 11:40:24 +0000
Subject: Bug #72408 [Fbk->Opn]: Coalescing operator on classes with overridden __get() method and NOT __isset()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201645@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72408&edit=1 ID: 72408 User updated by: kostasxx at gmail dot com Reported by: kostasxx at gmail dot com Summary: Coalescing operator on classes with overridden __get() method and NOT __isset() -Status: Feedback +Status: Open Type: Bug Package: Scripting Engine problem Operating System: Linux 4.1.13 PHP Version: 7.0.7 Block user comment: N Private report: N New Comment: Based on RFC, the use of coalescing operator should be equal to isset() and is based to the given example: // Fetches the request parameter user and results in 'nobody' if it doesn't exist $username = $_GET['user'] ?? 'nobody'; // equivalent to: $username = isset($_GET['user']) ? $_GET['user'] : 'nobody'; taken from here https://wiki.php.net/rfc/isset_ternary. So if you see in the updated code here https://3v4l.org/VUCFF, that isn't happening. It bypass isset() and goes to __get() directly. Previous Comments: ------------------------------------------------------------------------ [2016-06-15 11:33:26] requinix@php.net Why is the first test supposed to call __get but the second should not? Neither $attribute1 nor $attribute2 exist so the behavior should be the same for both. ------------------------------------------------------------------------ [2016-06-15 07:27:17] kostasxx at gmail dot com Description: ------------ When __get() method is overridden in a class and NOT the __isset(), when the null coalescing operator is used, the __get() is triggered instead of native isset(). This issue is related to https://bugs.php.net/bug.php?id=71359 Test script: --------------- https://3v4l.org/RMS3W ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72408&edit=1

« previous php.bugs (#201645) next »