RE: [PHP] different and logic between PHP4 and PHP5
| From: | Ford, Mike | Date: | Thu, 15 Mar 2007 10:36:45 +0000 |
| Subject: | RE: [PHP] different and logic between PHP4 and PHP5 | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-250646@lists.php.net to get a copy of this message | ||
On 14 March 2007 01:00, Larry Garfield wrote:
> On Tuesday 13 March 2007 7:50 am, Vieri wrote:
>
> > <?php
> > //$b=3;
> > $c=3;
> > $a=($b and $c);
> > echo "A = ".$a;
> > >
> >
> > in PHP4 I get:
> > A = 0
> > and in PHP5 I get:
> > A =
>
> > I could call this lazyness on our part or code
> > portability through PHP versions or better yet, bad
> > inherited coding right from the start.
>
> A little bit of each, I think. :-)
>
> "and", like &&, is a boolean operation. It will return
> either TRUE or FALSE.
> The string representation of TRUE and FALSE is, AFAIK, not
> defined.
Ahem. Yes it is. At http://php.net/manual/en/language.types.string.php#language.types.string.casting
it says:
> A boolean TRUE value is converted to the string "1", the
> FALSE value is represented as "" (empty string). This way
> you can convert back and forth between boolean and string
> values.
And I can testify from personal experience that this has been true since the very early days of
4.0.x (in fact, I still have a 4.0.5 installation hanging around that I tested it on...!!), so I do
not know where the *BLEEP* the OP can have been getting that 0 from.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm