php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48468 empty function confusing
Submitted: 2009-06-04 06:44 UTC Modified: 2009-06-04 09:40 UTC
From: heikki dot leppanen at extendeddisc dot com Assigned: bjori (profile)
Status: Closed Package: Translation problem
PHP Version: 5.2.5 OS: windows
Private report: No CVE-ID: None
 [2009-06-04 06:44 UTC] heikki dot leppanen at extendeddisc dot com
Description:
------------
class A {
   var $vars = {'a'=>'aa', 'b'=>'bb'};

function __get ($name) {
    return $this->vars[$name];
}
}

$x = new A();

if (empty($this->a))
    echo "this is empty");
else
    echo "this in not empty");


For me it looks a bug! Any experience?

Reproduce code:
---------------
---
From manual page: function.empty
---


Expected result:
----------------
This is not empty

Actual result:
--------------
RESULT:
this is empty


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-04 07:49 UTC] bjori@php.net
>    var $vars = {'a'=>'aa', 'b'=>'bb'};

Heh? What does this do and where did you find this snippet?

 [2009-06-04 08:08 UTC] heikki dot leppanen at extendeddisc dot com
It should be like this:

var $vars = array{'a'=>'aa', 'b'=>'bb'};
 [2009-06-04 08:20 UTC] bjori@php.net
That is incorrect too, where are you seeing this?

 [2009-06-04 08:50 UTC] heikki dot leppanen at extendeddisc dot com
OK, now the syntax is correct. This is only example from my code I wrote to demonstrate the confusing with empty()

class A {
   var $vars = array('a'=>'aa', 'b'=>'bb');

function __get ($name) {
    return $this->vars[$name];
}
}
$x = new A();

if (empty($x->a))
    echo "this is empty<br>";
else
    echo "this in not empty<br>";
 [2009-06-04 09:09 UTC] bjori@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

The __isset() overloading method is called, not __get()
 [2009-06-04 09:26 UTC] heikki dot leppanen at extendeddisc dot com
For me it looks like __get() is called. In my experience the only place where this is not working is empty().

class A {
   var $vars = array('a'=>'aa', 'b'=>'bb');

function __get ($name) {
    return $this->vars[$name];
}
}
$x = new A();

if (empty($x->a))
    echo "this is empty<br>";
else
    echo "this in not empty<br>";
echo "x->a::$x->a<br>";

Result is 
this is empty  // This is wrong
x->a::aa   // This is correct
 [2009-06-04 09:40 UTC] bjori@php.net
 __isset() is triggered by calling isset() or empty()  on inaccessible members. 

http://no.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members

And soon this will be on the isset(), empty() and unset() pages: http://news.php.net/php.doc.cvs/4114
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC