Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!news.internetdienste.de!noris.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <20840717.cCmZMDQWIF@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Tue, 03 Apr 2012 15:52:47 +0200 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit Subject: Re: A little tip Newsgroups: comp.lang.php References: Followup-To: comp.lang.php MIME-Version: 1.0 Lines: 49 NNTP-Posting-Date: 03 Apr 2012 15:52:49 CEST NNTP-Posting-Host: 2ce4cdab.newsspool4.arcor-online.net X-Trace: DXC=PlDSj@m?DYHA@P]\D4IUK On 3/30/2012 4:30 PM, Thomas Mlynarczyk wrote: >> Shelly schrieb: >>> $val = TRUE; >> >>> $val &= TRUE; >>> >>> which is identical to >>> >>> $val = $val && TRUE; >> >> No. &= is a bitwise operator while && means the logical AND operator. So >> when you do $val &= TRUE, PHP is trying to do TRUE & TRUE, but since >> bitwise operators only work with integers, TRUE is first coerced into >> the integer 1. So the operation ends up as 1 & 1 yielding the integer 1. >> Thus, $val = 1. The === operator checks the type of the operands which >> are int and bool and thus not the same, while == tries to convert the >> operands into something "comparable" and since they are both "truish" >> the result is TRUE here. > > Thank you. That makes a lot of sense. So, what I have to do if I want > to use === is to use the expanded form > > $val = $val && TRUE; You keep missing the point. That is _not_ "the expanded form" of anything. `&=' and `&&' are *different* operators; the first one is a *bitwise* operator, the second is a *logical* (boolean) one. In that sense, x = x & 1; is "the expanded form" of x &= 1; Please do not full-quote. PointedEars -- > If you get a bunch of authors […] that state the same "best practices" > in any programming language, then you can bet who is wrong or right... Not with javascript. Nonsense propagates like wildfire in this field. -- Richard Cornford, comp.lang.javascript, 2011-11-14