php empty object member
I am within a class. I try to set an object member:
$this->list = "hello";
print $this->l开发者_如何学JAVAist;
It returns "hello";
However, empty($this->list))
always return true.
But for non object member $tmp = "hello"
, empty($tmp)
return false.
Why empty()
cannot be used on object member?
Update: empty() is influenced by the the my code framework. That is why it does not work properly.
<?php
class Foo
{
var $bar;
function Bar()
{
$this->bar = 'hello';
echo "In class: " . (empty($this->bar) ? 'empty' : 'populated') . "\r\n";
}
}
$foo = new Foo();
$foo->Bar();
echo "Out of class: " . (empty($foo->bar) ? 'empty' : 'populated');
Output:
In class: populated
Out of class: populated
Not sure what you mean. Maybe provide more code? Also, per the empty()
manual, the following values are to be considered empty:
- "" (an empty string)
- 0 (0 as an integer)
- 0.0 (0 as a float) 9 "0" (0 as a string)
- NULL
- FALSE
- array() (an empty array)
- var $var; (a variable declared, but without a value in a class)
Also, try using var_dump
on the object to confirm it's what you're expecting.
精彩评论