[wp-hackers] DOING_AJAX all the time

Otto otto at ottodestruct.com
Wed Feb 1 04:23:16 UTC 2012


On Tue, Jan 31, 2012 at 5:30 PM, Steve Taylor <steve at sltaylor.co.uk> wrote:
> Duh - thanks!
>
> I always used to think that was a dodgy behaviour for constants (to
> return true when not defined). Then I forgot about it and they bit me
> again....

They don't return true when undefined, actually; they return strings.
It's just PHP making assumptions for you again.

Any undefined constant used like that is assumed to actually be an
unquoted static string. If you turn PHP Notices and error reporting
on, you'll see a message like this:

Notice:  Use of undefined constant WHATEVER - assumed 'WHATEVER' in
script.php on line 123

Basically it's evaluating that constant as the string instead. And any
string except the empty string is equivalent to "true" when used as a
boolean expression. So, there you go.

-Otto


More information about the wp-hackers mailing list