#40797 [Fbk->Opn]: empty() breaks when overloading with __get
ID: 40797 User updated by: stephan_schmidt at usa dot com Reported By: stephan_schmidt at usa dot com -Status: Feedback +Status: Open Bug Type: Class/Object related Operating System: Windows 200X PHP Version: 5.2.1 New Comment: The "Actual Results" were from the results of the above script run on a clean install of PHP 5.2.1 (Win 2000 SP4). No zend extensions are present or in use. The code above did not run as expected on any of the Win 200X servers it was tested on. Line 6 of the output read "int(5) empty" in every test case. I suspect it may have to do with the fact that empty() does not accept a function call as a parameter (i.e. empty(trim($myVar))) since overloading calls __get. However, one would expect it to also result in a fatal error if that were the case. Previous Comments: [2007-03-14 00:11:15] [EMAIL PROTECTED] That's exactly how it works here. Make sure you've disable any zend_extensions. ---- [2007-03-13 23:57:17] stephan_schmidt at usa dot com Description: When overloading with __get() to grab an index of an associative array inside an object, the overloaded variable returns 'false' when tested with empty() whether the value is empty or not (see Example 2 for incorrect results). Testing overloaded variables that were not in an associative array with empty() returns the expected results (Example 3). Reproduce code: --- 5, 'emptyVar' => ''); function __get($var) { return $this->myArray[$var]; } } class B { public $nonEmptyVar = 5; public $emptyVar = ''; function __get($var) { return $this->$var; } } $a = new A(); $b = new B(); echo 'Example 1:'; echo empty($a->myArray['nonEmptyVar']) ? 'empty' : 'not empty'; echo ''; echo empty($a->myArray['emptyVar']) ? 'empty' : 'not empty'; echo 'Example 2:'; var_dump($a->nonEmptyVar); echo empty($a->nonEmptyVar) ? 'empty' : 'not empty'; echo ''; var_dump($a->emptyVar); echo empty($a->emptyVar) ? 'empty' : 'not empty'; echo 'Example 3:'; echo empty($b->nonEmptyVar) ? 'empty' : 'not empty'; echo ''; echo empty($b->emptyVar) ? 'empty' : 'not empty'; ?> Expected result: Example 1: not empty empty Example 2: int(5) not empty string(0) "" empty Example 3: not empty empty Actual result: -- Example 1: not empty empty Example 2: int(5) empty string(0) "" empty Example 3: not empty empty -- Edit this bug report at http://bugs.php.net/?id=40797&edit=1
#40797 [NEW]: empty() breaks when overloading with __get
From: stephan_schmidt at usa dot com Operating system: Windows 200X PHP version: 5.2.1 PHP Bug Type: Class/Object related Bug description: empty() breaks when overloading with __get Description: When overloading with __get() to grab an index of an associative array inside an object, the overloaded variable returns 'false' when tested with empty() whether the value is empty or not (see Example 2 for incorrect results). Testing overloaded variables that were not in an associative array with empty() returns the expected results (Example 3). Reproduce code: --- 5, 'emptyVar' => ''); function __get($var) { return $this->myArray[$var]; } } class B { public $nonEmptyVar = 5; public $emptyVar = ''; function __get($var) { return $this->$var; } } $a = new A(); $b = new B(); echo 'Example 1:'; echo empty($a->myArray['nonEmptyVar']) ? 'empty' : 'not empty'; echo ''; echo empty($a->myArray['emptyVar']) ? 'empty' : 'not empty'; echo 'Example 2:'; var_dump($a->nonEmptyVar); echo empty($a->nonEmptyVar) ? 'empty' : 'not empty'; echo ''; var_dump($a->emptyVar); echo empty($a->emptyVar) ? 'empty' : 'not empty'; echo 'Example 3:'; echo empty($b->nonEmptyVar) ? 'empty' : 'not empty'; echo ''; echo empty($b->emptyVar) ? 'empty' : 'not empty'; ?> Expected result: Example 1: not empty empty Example 2: int(5) not empty string(0) "" empty Example 3: not empty empty Actual result: -- Example 1: not empty empty Example 2: int(5) empty string(0) "" empty Example 3: not empty empty -- Edit bug report at http://bugs.php.net/?id=40797&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40797&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40797&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40797&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40797&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40797&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40797&r=needtrace Need Reproduce Script:http://bugs.php.net/fix.php?id=40797&r=needscript Try newer version:http://bugs.php.net/fix.php?id=40797&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40797&r=support Expected behavior:http://bugs.php.net/fix.php?id=40797&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40797&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40797&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40797&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40797&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40797&r=dst IIS Stability:http://bugs.php.net/fix.php?id=40797&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40797&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40797&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40797&r=nozend MySQL Configuration Error:http://bugs.php.net/fix.php?id=40797&r=mysqlcfg