IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New PHP 'empty' Oddity
I am getting the following error:

Parse error: parse error, expecting `T_VARIABLE' or `'$'' in ....\\test.php on line 3

From this code:

<?php

$foo = empty(0);

?>

My work-around is to write a "myEmpty()" function instead of the built-in.
________________
oop.ismad.com
Expand Edited by tablizer Nov. 12, 2002, 12:15:37 AM EST
Expand Edited by tablizer Nov. 12, 2002, 12:17:09 AM EST
New That construct isn't supposed to work.
empty() only works on variables. Actually, you might prefer to use isset(); I think empty() will succeed if the variable can be evaluated to 0.

Despite looking like a function, empty() isn't a real function; it's a language operator. No I don't like this either, but that's how it works. isset(), unset(), list() and array() have similar characteristics: they look like functions, but they aren't.

Wade.

"Ah. One of the difficult questions."

New No function results either? You've gotta be kidding
empty() only works on variables.

What the fluck? You're kidding! It does not work on *function results* either.
\n<?php\n\n$x = empty(myFunc('foo'));\n\nfunction myFunc($a) {\nreturn($a . 'blah');\n}\n\n?>\n

What in Buddah's name were they thinking??? Substitability is a fundimental need of programming.

[empty()] they look like functions, but they aren't.

They are "fucktions"!

I noticed that the documentation at php.net has
changed for it. There used to be a bunch of
notes on it and how it differed from isset().
That is all gone now it seems. Note that it
says that isset() is also a "language construct".

Thanks for enlightening me.
Expand Edited by tablizer Nov. 12, 2002, 02:04:52 PM EST
New What are you actually trying to check for?
I very rarely use empty() but I use is_null() a bit and isset() a lot. IMO, empty() is vestigial. PHP doesn't actually have a concept of "empty".

I much prefer Icon's approach: not-set variables are semantically identical to those containing &null which can be passed like any other value. Icon also has prefix operators / and \\ which mean check for null and check for not-null. Much cleaner than PHP's isset().

Wade.

"Ah. One of the difficult questions."

New type agnostic
"Empty" is a lot like XBase's "empty" :-) You don't have to worry about whether it is a string or number. You can later change the "type" for example, and not worry about code not working. Also, some databases don't have null number defaults (by vendor or DBA decision), but initialize to zero. Thus, it also makes it more DB vendor agnostic. IOW, "maintenance friendly". I like it.

Regardless, I think accepting only variables and NOT functions nor constants is just plain dumb! (for all the "language constructs", not just "empty".)
________________
oop.ismad.com
     PHP 'empty' Oddity - (tablizer) - (4)
         That construct isn't supposed to work. - (static) - (3)
             No function results either? You've gotta be kidding - (tablizer) - (2)
                 What are you actually trying to check for? - (static) - (1)
                     type agnostic - (tablizer)

For Wade, it is to laugh.
79 ms