Re: [PHP] conditional statement problems

2002-10-01 Thread Tom Rogers

Hi,

Tuesday, October 1, 2002, 5:11:08 PM, you wrote:
PO $title_err = ($adTitle == ) ? 1 : strlen($adTitle)  50 ? 2 : 0;

PO Can anyone tell me why this is not evaluating correctly (returning a
PO value of 1) when $adTitle is an empty string?


It is right according to your expression, try  ($adTitle != )

-- 
regards,
Tom


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] conditional statement problems

2002-10-01 Thread René Moonen

Pablo Oliva wrote:

$title_err = ($adTitle == ) ? 1 : strlen($adTitle)  50 ? 2 : 0;

Can anyone tell me why this is not evaluating correctly (returning a
value of 1) when $adTitle is an empty string?


  

I have no idea... but if you change your code to this, it works:

$title_err = ($adTitle == ) ? 1 : (strlen($adTitle)  50 ? 2 : 0);

Does anyone know why ?



René




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] conditional statement problems

2002-10-01 Thread René Moonen

René Moonen wrote:

 Pablo Oliva wrote:

 $title_err = ($adTitle == ) ? 1 : strlen($adTitle)  50 ? 2 : 0;

 Can anyone tell me why this is not evaluating correctly (returning a
 value of 1) when $adTitle is an empty string?


  

 I have no idea... but if you change your code to this, it works:

 $title_err = ($adTitle == ) ? 1 : (strlen($adTitle)  50 ? 2 : 0);

 Does anyone know why ?



 René




Yes... that's it. Your statement is probably evaluated like this:

$title_err = ( ($adTitle == ) ? 1 : strlen($adTitle)  50 ) ? 2 : 0;

The first ?: returns 1 so the second ?: will return 2


Regards


René



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] conditional statement problems

2002-10-01 Thread Ford, Mike [LSS]



 -Original Message-
 From: Pablo Oliva [mailto:[EMAIL PROTECTED]]
 Sent: 01 October 2002 08:11
 To: [EMAIL PROTECTED]
 Subject: [PHP] conditional statement problems
 
 
 $title_err = ($adTitle == ) ? 1 : strlen($adTitle)  50 ? 2 : 0;
 
 Can anyone tell me why this is not evaluating correctly (returning a
 value of 1) when $adTitle is an empty string?

Yes.  According to the list at http://uk.php.net/manual/en/language.operators.php, the 
?: operator is left-associative, and of lesser precedence than , so your expression 
is equivalent to the following:

   (($adTitle == ) ? 1 : strlen($adTitle)  50) ? 2 : 0

... and you can probably see why that is giving the wrong answer!  You need to use 
parentheses to force the order of evaluation you want, thus:

   ($adTitle == ) ? 1 : (strlen($adTitle)  50 ? 2 : 0)

(Incidentally, if you've programmed in c or derivatives, this will come as a surprise 
since in c ?: is right-associative and would give your desired result without the 
additional parentheses.)

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php