Re: [RFC] Comparison and conversion inconsistency - need more info

From: Date: Sat, 16 Nov 2013 17:16:43 +0000
Subject: Re: [RFC] Comparison and conversion inconsistency - need more info
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Groups: php.internals 
Request: Send a blank email to internals+get-70175@lists.php.net to get a copy of this message
On Sat, Nov 16, 2013 at 6:22 AM, Marc Bennewitz <php@marc-bennewitz.de>wrote: > Hi, > > What about the following PHP logic: > var_dump(null == 0); // TRUE > var_dump(null < -1); // TRUE > var_dump(null > -1); // FALSE > > How can you explain that ? > > Greetings > Marc > > false ==false // TRUE false < true // TRUE false > true // FALSE It's right here: http://www.php.net/manual/en/language.operators.comparison.php. Halfway down the page, type of op 1 is null, op 2 is anything. -- William Bartlett College of Engineering | Cornell University '14 240-432-5189 > Am 15.11.2013 00:03, schrieb Yasuo Ohgaki: > > Hi all, > > > > On Tue, Nov 12, 2013 at 4:03 AM, Sanford Whiteman < > > swhitemanlistens-software@cypressintegrated.com> wrote: > > > >>> You don't have to think the current documentation is awful to find ways > >>> of improving it. > >> > >> Sure, go for it! > > > > > > I wrote my misunderstanding to my personal blog. It seems many people > > misunderstand it, just like me :) > > > > Any improvement/correction? > > min() manual page is better to be updated. I'll add min() example blow to > > min() manual > > page also. > > > > Index: operators.xml > > =================================================================== > > --- operators.xml (リビジョン 332115) > > +++ operators.xml (作業コピー) > > @@ -1262,7 +1262,7 @@ > > <row> > > <entry><type>bool</type> or > > <type>null</type></entry> > > <entry>anything</entry> > > - <entry>Convert to <type>bool</type>, &false; &lt; > > &true;</entry> > > + <entry>Convert to <type>bool</type> both side, &false; > > &lt; > > &true;</entry> > > </row> > > <row> > > <entry><type>object</type></entry> > > @@ -1298,8 +1298,28 @@ > > </tbody> > > </tgroup> > > </table> > > + > > <para> > > <example> > > + <title>Boolean/null comparison</title> > > + <programlisting role="php"> > > +<![CDATA[ > > +<?php > > +// Bool and null are compared as bool always > > +var_dump(1 == TRUE); // TRUE - same as (bool)1 == TRUE > > +var_dump(0 == FALSE); // TRUE - same as (bool)0 == FALSE > > +var_dump(100 < TRUE); // FALSE - same as (bool)100 < TRUE > > +var_dump(-10 < FALSE);// FALSE - same as (bool)-10 < FALSE > > +var_dunp(min(-100,-10, NULL, 10, 100); // NULL - (bool)NULL < (bool)-100 > > is FALSE < TRUE > > +?> > > +]]> > > + </programlisting> > > + </example> > > + </para> > > + > > + > > + <para> > > + <example> > > <title>Transcription of standard array comparison</title> > > <programlisting role="php"> > > <![CDATA[ > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.internals (#70175) next »