Re: different and logic between PHP4 and PHP5

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



--- Richard Lynch <ceo@xxxxxxxxx> wrote:

> On Mon, March 12, 2007 1:53 pm, Vieri wrote:
> > The following code:
> >
> > <?php
> > $b="";
> > $c="df";
> > $a=($b and $c);
> 
> Why in the world would you use 'and' on two strings?
> 
> What is that supposed to even mean?...
> 
> Type-cast them to numbers if you want to use 'and'

I didn't code this. We have inherited some code that
worked this way in php4:
if string1 and string2 exist then return true or 1
else return false or 0
in php5 it just doesn't behave the same way.

In any case, even if I use numbers I get the same
behavior:

<?php
//$b=3;
$c=3;
$a=($b and $c);
echo "A = ".$a;
?>

in PHP4 I get:
A = 0
and in PHP5 I get:
A = 

type-casting as suggested earlier by another list user
(eg. (int)$a) would require making sure we change the
source code in each and every instance of the web site
applications.
I also thought of casting before the rest of the code
(as in a include("pre.php") and hopefully leaving most
of the original code untouched):
<?php
settype($a,int);
settype($b,int);
settype($c,int);
$a = (int) $a;
$b = (int) $b;
$c = (int) $c;
//$b=3;
$c=3;
$a=($b and $c);
echo "A = ".$a;
?>
But it still doesn't behave the same way in PHP4 and
PHP5 unless I change the last line to: 
echo "A = ".(int)$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.

Anyway, I was hoping there were some option in global
PHP settings that could make PHP4 and PHP5 behave the
exact same way as far as the above example is
concerned before starting to rewrite the scripts. ;-(

Thanks anyway and sorry for the "strange post".



 
____________________________________________________________________________________
Finding fabulous fares is fun.  
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.
http://farechase.yahoo.com/promo-generic-14795097

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux