[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Edlug Archive Mar 2004 ]

Re: [edlug] PHP Problem




Confirmed.

This:

    http://bugs.php.net/bug.php?id=25356

seems to imply that in php, the ternary is evaluated right-to-left,
though I can't say that I understand why.

Hope that helps (or at least verifies) :-)


Robert
rgorrie@xxx.xxx.xxx


On Thu, 11 Mar 2004 00:21:02 -0000, "Malcolm McLean"
<Malcolm.McLean@xxx.xxx.xxx> said:
> 
> Hi folks,
> 
> I'm using apache 2 and PHP 4.3.4  and I'm getting some unexpected
> behaviour.  The following code:
> 
> 	$v1 = "val 1";
> 	$v2 = "val 2";
> 	$v3 = "val 3";
> 
> 	$val = $v1 ? $v1 : $v2 ? $v2 : $v3;
> 
> 	echo $val;
> 
> yields "val 2",  I would have expected it to yield "val 1", as does
> 
> 	$val = $v1 ? $v1 : ($v2 ? $v2 : $v3);
> 
> Can anyone confirm this?
> 
> 
> -
> ----------------------------------------------------------------------
> You can find the EdLUG mailing list FAQ list at:
> http://www.edlug.org.uk/list_faq.html
-
----------------------------------------------------------------------
You can find the EdLUG mailing list FAQ list at:
http://www.edlug.org.uk/list_faq.html



This archive is kept by wibble@morpheux.org.DONTSPAMME
homepage