Bug #68243 [Opn->Fbk]: IMPORTANT! Checking empty value failed

From: Date: Thu, 01 Dec 2016 17:27:38 +0000
Subject: Bug #68243 [Opn->Fbk]: IMPORTANT! Checking empty value failed
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205722@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68243&edit=1 ID: 68243 Updated by: cmb@php.net Reported by: Siemienik dot Pawel at gmail dot com Summary: IMPORTANT! Checking empty value failed -Status: Open +Status: Feedback Type: Bug Package: *PDF functions Operating System: Ubuntu 14 PHP Version: 5.5.17 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with , is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. Previous Comments: ------------------------------------------------------------------------ [2014-10-18 17:02:28] keithm at aoeex dot com Forgot to try with a non-empty value, which does shows the symptom. From the documentation however: ------- Note: When using empty() on inaccessible object properties, the __isset() overloading method will be called, if declared. ------- You need to implement __isset() if you want to check whether magic properties exist. Explanation: Adding the () inside the empty call means that empty checks the result of the expression, which will be the string value returned by __get. Without the () PHP will check the if the property exists on the object instead. empty(A::getInstance()->title) is equivalent to !isset(A::getInstance()->title) || !A::getInstance()->title; whereas empty((A::getInstance()->title)) is equivalent to ($var = A::getInstance()->title) && (!isset($var) || !$var); ------------------------------------------------------------------------ [2014-10-18 16:39:17] keithm at aoeex dot com Works for me If you believe this is a problem, provide a small but complete test script (including class definitions) which will reproduce the problem. Test Script: ----------------------------------------------------------------- <?php class A { static $instance; public static function getInstance(){ if (!self::$instance){ self::$instance=new self; } return self::$instance; } public function __get($nm){ return ''; } } var_dump( !empty(A::getInstance()->title) , !empty((A::getInstance()->title)) , !empty((A::getInstance()->title)) !== empty(A::getInstance()->title) ); Result: ----------------------------------------------------------------- bool(false) bool(false) bool(true) Version: ----------------------------------------------------------------- Linux: PHP 5.5.9-1ubuntu4.4 (cli) (built: Sep 4 2014 06:56:34) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies Windows: PHP 5.5.18 (cli) (built: Oct 15 2014 13:04:56) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies ------------------------------------------------------------------------ [2014-10-16 12:27:59] siemienik dot pawel at gmail dot com int AnyClass is function __get(), which will return string value; ------------------------------------------------------------------------ [2014-10-16 12:25:00] Siemienik dot Pawel at gmail dot com Description: ------------ !empty((AnyClass::getInstance()->title)) !== !empty(AnyClass::getInstance()->title) Test script: --------------- var_dump( !empty((AnyClass::getInstance()->title)), !empty(AnyClass::getInstance()->title) ) if(!empty((AnyClass::getInstance()->title)) !== empty(AnyClass::getInstance()->title)) var_dump('BIG PROBLEM HERE!') ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68243&edit=1

« previous php.bugs (#205722) next »