php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20018 empty($this->property) always returns TRUE inside class method
Submitted: 2002-10-21 23:28 UTC Modified: 2002-11-02 23:04 UTC
From: tater at potatoe dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4CVS-2002-10-21 OS: OS X 10.1
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tater at potatoe dot com
New email:
PHP Version: OS:

 

 [2002-10-21 23:28 UTC] tater at potatoe dot com
empty() seems to always return TRUE when testing an object
property from inside a method of the object. it works OK 
on regular variables, or when testing the property externally.

test code:
<?php
class test
{
    function test()
    {
        $this->x = NULL;
        print "<li>this->x={$this->x}\n";
        print "<li>is this->x empty? ".(empty($this->x) ? "yes" : "no")."\n";
        $this->x = 'i am not empty';
        print "<li>this->x={$this->x}\n";
        print "<li>is this->x empty? ".(empty($this->x) ? "yes" : "no")."\n";
        $x = NULL;
        print "<li>x={$x}\n";
        print "<li>is x empty? ".(empty($x) ? "yes" : "no")."\n";
        $x = 'i am not empty';
        print "<li>x={$x}\n";
        print "<li>is x empty? ".(empty($x) ? "yes" : "no")."\n";
    }
}
$x = new test;
?>

output:
<li>this->x=
<li>is this->x empty? yes
<li>this->x=i am not empty
<li>is this->x empty? yes
<li>x=
<li>is x empty? yes
<li>x=i am not empty
<li>is x empty? no

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-02 11:00 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip


 [2002-11-02 23:04 UTC] tater at potatoe dot com
Fixed in latest CVS release.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Dec 31 06:00:02 2025 UTC