cvs: /phpdoc/language types.sgml

From: Date: Mon, 15 Nov 1999 21:51:32 +0000
Subject: cvs: /phpdoc/language types.sgml
Groups: php.dev 
Request: Send a blank email to php-dev+get-12571@lists.php.net to get a copy of this message
cslawi Mon Nov 15 16:51:32 1999 EDT Modified files: /phpdoc/language types.sgml Log: Add note regarding current behaviour of automatic conversion to array. Index: phpdoc/language/types.sgml diff -u phpdoc/language/types.sgml:1.7 phpdoc/language/types.sgml:1.8 --- phpdoc/language/types.sgml:1.7 Sun Nov 14 19:50:48 1999 +++ phpdoc/language/types.sgml Mon Nov 15 16:51:30 1999 @@ -1,16 +1,17 @@ <chapter id="language.types"> - <title>Types</title> + <title>Types</title> <para> PHP supports the following types: <itemizedlist> - <listitem><simpara><link linkend="language.types.integer">integer</link></simpara></listitem> - <listitem><simpara><link linkend="language.types.double">floating-point numbers</link></simpara></listitem> - <listitem><simpara><link linkend="language.types.string">string</link></simpara></listitem> <listitem><simpara><link linkend="language.types.array">array</link></simpara></listitem> + <listitem><simpara><link linkend="language.types.double">floating-point numbers</link></simpara></listitem> + <listitem><simpara><link linkend="language.types.integer">integer</link></simpara></listitem> <listitem><simpara><link linkend="language.types.object">object</link></simpara></listitem> - </itemizedlist></para> + <listitem><simpara><link linkend="language.types.string">string</link></simpara></listitem> + </itemizedlist> + </para> <simpara> The type of a variable is usually not set by the programmer; @@ -18,14 +19,18 @@ in which that variable is used.</simpara> <simpara> - If you would like to force a variable to be converted to a certain - type, you may either <link linkend="language.types.typecasting">cast</link> the variable or use - the <function>settype</function> function on it.</simpara> + If you would like to force a variable to be converted to a certain + type, you may either <link + linkend="language.types.typecasting">cast</link> the variable or + use the <function>settype</function> function on it.</simpara> <simpara> Note that a variable may behave in different manners in certain situations, depending on what type it is at the time. For more - information, see the section on <link linkend="language.types.type-juggling">Type Juggling</link>.</simpara> + information, see the section on <link + linkend="language.types.type-juggling">Type + Juggling</link>. + </simpara> <sect1 id="language.types.integer"> <title>Integers</title> @@ -364,7 +369,8 @@ assign a string value to variable <parameter>var</parameter>, <parameter>var</parameter> becomes a string. If you then assign an integer value to <parameter>var</parameter>, it becomes an - integer.</simpara> + integer. + </simpara> <para> An example of PHP's automatic type conversion is the addition @@ -387,14 +393,65 @@ </informalexample></para> <simpara> - If the last two examples above seem odd, see <link linkend="language.types.string.conversion">String conversion</link>.</simpara> + If the last two examples above seem odd, see <link + linkend="language.types.string.conversion">String + conversion</link>. + </simpara> <simpara> If you wish to force a variable to be evaluated as a certain - type, see the section on <link linkend="language.types.typecasting">Type casting</link>. If you + type, see the section on <link + linkend="language.types.typecasting">Type casting</link>. If you wish to change the type of a variable, see - <function>settype</function>.</simpara> + <function>settype</function>. + </simpara> + + <note> + <para> + The behaviour of an automatic conversion to array is currently + undefined. + + <informalexample> + <programlisting> +$a = 1; // $a is an integer +$a[0] = "f"; // $a becomes an array, with $a[0] holding "f" + </programlisting> + </informalexample> + </para> + + <para> + While the above example may seem like it should clearly result in + $a becoming an array, the first element of which is 'f', + consider this: + + <informalexample> + <programlisting> +$a = "1"; // $a is a string +$a[0] = "f"; // What about string offsets? What happens? + </programlisting> + </informalexample> + + </para> + + <para> + Since PHP supports indexing into strings via offsets using the + same syntax as array indexing, the example above leads to a + problem: should $a become an array with its first element being + "f", or should "f" become the first character of the string $a? + </para> + + <para> + For this reason, as of PHP 3.0.12 and PHP 4.0b3-RC4, the result + of this automatic conversion is considered to be + undefined. Fixes are, however, being discussed. + </para> + + </note> + + + + <sect2 id="language.types.typecasting"> <title>Type casting</title> @@ -438,7 +495,9 @@ - </para></sect2></sect1> + </para> + </sect2> + </sect1> </chapter>

« previous php.dev (#12571) next »