Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #4089
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: empty - not empty() |
| Date | 2011-12-19 18:48 +0100 |
| Message-ID | <9l9bo5FelbU1@mid.individual.net> (permalink) |
| References | <iNGdnbO2--gpznLTnZ2dnUVZ_hCdnZ2d@cablespeedmi.com> |
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
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
empty - not empty() bill <nobody@spamcop.net> - 2011-12-19 10:09 -0500
Re: empty - not empty() "J.O. Aho" <user@example.net> - 2011-12-19 18:48 +0100
Re: empty - not empty() Chuck Anderson <cycletourist@invalid.invalid> - 2011-12-19 18:14 -0700
Re: empty - not empty() bill <nobody@spamcop.net> - 2011-12-20 08:14 -0500
Re: empty - not empty() "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2011-12-20 17:40 +0100
Re: empty - not empty() bill <nobody@spamcop.net> - 2011-12-20 18:44 -0500
csiph-web