Re: Logical OR in assignment

From: Date: Thu, 28 Sep 2006 08:09:53 +0000
Subject: Re: Logical OR in assignment
References: 1  Groups: php.general php.general 
Request: Send a blank email to php-general+get-242339@lists.php.net to get a copy of this message
Jason Karns wrote:
I once saw the use of OR (|) in assignment. $x = $y | $z; Does this use bitwise OR? I'm trying to see if I could use the above expression in place of: $x = is_null($y) ? $z : $y;
yes, '|' is bitwise OR, but that is /not/ a ternary operator. it's not safe to just replace the ternary operation with the bitwise operation. for example, if $y=5 and $z=9, then:
$x=$y|$z;             -> $x=13
$x=is_null($y)?$z:$y; -> $x=5 Kae

« previous php.general (#242339) next »