Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: empty - not empty() Date: Mon, 19 Dec 2011 18:48:53 +0100 Lines: 36 Message-ID: <9l9bo5FelbU1@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 6or6bY3F4Bs5ovrASD92AwWGPwMr7zMxnjpG1BiXV8NK+puSYK Cancel-Lock: sha1:uZH42C0SjMAoedCOGCfSoxLWx/I= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0.1) Gecko/20111204 Firefox/8.0.1 SeaMonkey/2.5 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.php:4089 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