FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » empty - not empty()
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: empty - not empty() [message #176292 is a reply to message #176291] Mon, 19 December 2011 17:48 Go to previous messageGo to previous message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma:
Senior Member
bill wrote:
> searching the manual gives lots of hits, none of which appear relevant (at
> least by the title).
>
> I had the following code in a scheduling class:
>
> if ($ptNum == "empty") {
> $ptNum = 0;
> $status= "e";
> }
>
> I pass the string "empty" to the function as a patient number if we are
> creating an empty appointment slot.
>
> now, this fails because with a patient number of 0 the if returns true.
>
> I am aware of the function empty() that would work like that, but do not
> understand why the compare fails with the constant, "empty."

I assume you are comparing 0 and not the string "0", this makes you are
comparing integer with string, there ain't any type conversion done.
The zero is always equal to a string, there is a slightly more information at

http://php.net/manual/en/language.operators.comparison.php


> I fixed the function by making it a strict compare, but would like to know why
> the regular compare is true with the numeric value of zero.

I would say it's not the right way to compare, use strcmp, is_numeric and so
on, to make a proper compare instead of using the comparison operator.


--

//Aho
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: FastCGI + ignore_user_abort
Next Topic: united governments of planet earth
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 02:13:31 GMT 2024

Total time taken to generate the page: 0.04153 seconds