|
Posted by Marcin Dobrucki on 08/22/05 12:54
ZeldorBlat wrote:
> Check out the following:
>
> http://www.php.net/manual/en/function.empty.php
>
> empty() and isset() only work on variables. In your case,
> $a->getValue() is the return value of a function -- not a variable.
> You could do something like:
Yea, thanks. I noticed this just as I posted the article, and then
promply canceled it, but it seems it didn't get canceled everywhere.
the is_int and is_null work differently, and it threw me off a bit.
> $a = new A();
> $v = $a->getValue();
> if (!empty($v)) {
> echo "success";
> }
> else {
> echo "failure";
> }
Yes, that's how I do it now. A bit of fuss, but works.
> Alternatively, you could define your own isEmpty() function which does
> whatever you want. It could be as simple as:
>
> function isEmpty($value) {
> return (strlen($value) == 0);
> }
Yes, but again, "empty" checks for null, 0, etc. Which is useful.
> Also, as of PHP 5.1 you can overload calls to empty() and isset() on
> object properties. Most useful when you also overload the getters and
> settings (via __get() and __set()).
Will have a lookie, but still working in 4.x level (and it's not
going to change anytime soon). Thanks.
/Marcin
Navigation:
[Reply to this message]
|