#43697 [Opn->Bgs]: converting null variable to object type will make the variable non empty

From: Date: Sun, 30 Dec 2007 16:27:29 +0000
Subject: #43697 [Opn->Bgs]: converting null variable to object type will make the variable non empty
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-120944@lists.php.net to get a copy of this message
ID: 43697 Updated by: iliaa@php.net Reported By: packard_bell_nec at hotmail dot com -Status: Open +Status: Bogus Bug Type: Variables related Operating System: windows server 2003 r2 PHP Version: 5.2.5 New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php This is an expected behavior and yes it did change from 5.0/5.1 days. An empty object is no longer considered to be "empty". Previous Comments: ------------------------------------------------------------------------ [2007-12-28 11:17:05] packard_bell_nec at hotmail dot com Description: ------------ When I write the codes concerning type conversion, I found the entitled "bug". Then, I check the documentation, and I found the statement "an object with zero member variables (PHP 4 only) is considered FALSE" in~ http://php.net/manual/en/language.types.boolean.php However, I am NOT going to ask for reopening the above "feature". Instead, I am going to ask for correcting the "bug" so that "an object with class stdClass and zero member variables is considered FALSE". The behavior of empty() should also be changed accordingly. The extensions that I used: [PHP_GD2] extension=php_gd2.dll [PHP_MBSTRING] extension=php_mbstring.dll [PHP_MCRYPT] extension=php_mcrypt.dll [PHP_MYSQL] extension=php_mysql.dll [PHP_MYSQLI] extension=php_mysqli.dll [Zend] zend_extension_ts="C:\Program Files\PHP\lib\ZendExtensionManager.dll" zend_extension_manager.optimizer_ts="C:\Program Files\PHP\lib\Optimizer-3.3.0" zend_extension_manager.debug_server_ts="C:\Program Files\PHP\lib\Debugger-5.2.10" Reproduce code: --------------- $foo = null; settype($foo, 'object'); $cv_foo = get_class_vars(get_class($foo)); $ov_foo = get_object_vars($foo); echo gettype($foo).'<br/>'.get_class($foo).'<br/>'.var_export($cv_foo, true).'<br/>'.var_export($ov_foo, true).'<br/>'.isset($foo).'<br/>'.!empty($foo).'<br/>'.var_export($foo, true).'<br/><br/>'; $goo = null; settype($goo, 'array'); echo gettype($goo).'<br/>'.isset($goo).'<br/>'.!empty($goo).'<br/>'.var_export($goo, true).'<br/><br/>'; $hoo = false; settype($hoo, 'object'); $cv_hoo = get_class_vars(get_class($hoo)); $ov_hoo = get_object_vars($hoo); echo gettype($hoo).'<br/>'.get_class($hoo).'<br/>'.var_export($cv_hoo, true).'<br/>'.var_export($ov_hoo, true).'<br/>'.isset($hoo).'<br/>'.!empty($hoo).'<br/>'.var_export($hoo, true).'<br/><br/>'; $joo = false; settype($joo, 'array'); echo gettype($joo).'<br/>'.isset($joo).'<br/>'.!empty($joo).'<br/>'.var_export($joo, true).'<br/><br/>'; Expected result: ---------------- object stdClass array ( ) array ( ) 1 stdClass::__set_state(array( )) array 1 array ( ) object stdClass array ( ) array ( 'scalar' => false, ) 1 1 stdClass::__set_state(array( 'scalar' => false, )) array 1 1 array ( 0 => false, ) Actual result: -------------- object stdClass array ( ) array ( ) 1 1 stdClass::__set_state(array( )) array 1 array ( ) object stdClass array ( ) array ( 'scalar' => false, ) 1 1 stdClass::__set_state(array( 'scalar' => false, )) array 1 1 array ( 0 => false, ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43697&edit=1

« previous php.bugs (#120944) next »