php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43697 converting null variable to object type will make the variable non empty
Submitted: 2007-12-28 11:17 UTC Modified: 2007-12-30 16:27 UTC
From: packard_bell_nec at hotmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.2.5 OS: windows server 2003 r2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: packard_bell_nec at hotmail dot com
New email:
PHP Version: OS:

 

 [2007-12-28 11:17 UTC] 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,
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-30 16:27 UTC] iliaa@php.net
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".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 13:01:33 2025 UTC