Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 3020

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>Expression types</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Migrating from PHP/FI 2 to PHP 3"
HREF="migration.html"><LINK
REL="PREVIOUS"
TITLE="while syntax"
HREF="migration.while.html"><LINK
REL="NEXT"
TITLE="Error messages have changed"
HREF="migration.errors.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="section"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="migration.while.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Appendix C. Migrating from PHP/FI 2 to PHP 3</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="migration.errors.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="migration.expr"
></A
>Expression types</H1
><P
>&#13;   PHP/FI 2.0 used the left side of expressions to determine what type
   the result should be.  PHP 3.0 takes both sides into account when
   determining result types, and this may cause 2.0 scripts to behave
   unexpectedly in 3.0.
  </P
><P
>&#13;   Consider this example:
   <DIV
CLASS="informalexample"
><A
NAME="AEN104264"
></A
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>$a[0]=5;
$a[1]=7;

$key = key($a);
while ("" != $key) {
    echo "$keyn";
    next($a);
}</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>

   In PHP/FI 2.0, this would display both of $a's indices.  In PHP
   3.0, it wouldn't display anything.  The reason is that in PHP 2.0,
   because the left argument's type was string, a string comparison
   was made, and indeed <TT
CLASS="literal"
>""</TT
> does not equal
   <TT
CLASS="literal"
>"0"</TT
>, and the loop went through.  In PHP 3.0,
   when a string is compared with an integer, an integer comparison is
   made (the string is converted to an integer).  This results in
   comparing <TT
CLASS="literal"
>atoi("")</TT
> which is
   <TT
CLASS="literal"
>0</TT
>, and <TT
CLASS="literal"
>variablelist</TT
> which is
   also <TT
CLASS="literal"
>0</TT
>, and since <TT
CLASS="literal"
>0==0</TT
>, the
   loop doesn't go through even once.
  </P
><P
>&#13;   The fix for this is simple.  Replace the while statement with:
   <DIV
CLASS="informalexample"
><A
NAME="AEN104274"
></A
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>while ((string)$key != "") {</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="migration.while.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="migration.errors.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>while syntax</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="migration.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Error messages have changed</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>