cvs: /phpdoc/language types.sgml

From: Date: Tue, 16 Nov 1999 02:23:41 +0000
Subject: cvs: /phpdoc/language types.sgml
Groups: php.dev 
Request: Send a blank email to php-dev+get-12590@lists.php.net to get a copy of this message
cslawi Mon Nov 15 21:23:41 1999 EDT Modified files: /phpdoc/language types.sgml Log: Document the behaviour of $arr = (array) $scalar; and $obj = (object) $scalar; Index: phpdoc/language/types.sgml diff -u phpdoc/language/types.sgml:1.8 phpdoc/language/types.sgml:1.9 --- phpdoc/language/types.sgml:1.8 Mon Nov 15 16:51:30 1999 +++ phpdoc/language/types.sgml Mon Nov 15 21:23:40 1999 @@ -16,13 +16,15 @@ <simpara> The type of a variable is usually not set by the programmer; rather, it is decided at runtime by PHP depending on the context - in which that variable is used.</simpara> + 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> + use the <function>settype</function> function on it. + </simpara> <simpara> Note that a variable may behave in different manners in certain @@ -145,7 +147,8 @@ <simpara> When the first expression is a string, the type of the variable - will depend on the second expression.</simpara> + will depend on the second expression. + </simpara> <informalexample> <programlisting> @@ -162,8 +165,23 @@ <simpara> For more information on this conversion, see the Unix manual - page for strtod(3).</simpara></sect2></sect1> + page for strtod(3). + </simpara> + <para> + If you would like to test any of the examples in this section, you + can cut and paste the examples and insert the following line to see + for yourself what's going on: + <informalexample> + <programlisting> +echo "\$foo==$foo; type is " . gettype( $foo ) . "&lt;br&gt;\n"; + </programlisting> + </informalexample> + </para> + + </sect2> + </sect1> + <sect1 id="language.types.array"> <title>Arrays</title> @@ -406,6 +424,17 @@ <function>settype</function>. </simpara> + <para> + If you would like to test any of the examples in this section, you + can cut and paste the examples and insert the following line to + see for yourself what's going on: + <informalexample> + <programlisting> +echo "\$foo==$foo; type is " . gettype( $foo ) . "&lt;br&gt;\n"; + </programlisting> + </informalexample> + </para> + <note> <para> @@ -491,11 +520,34 @@ <para> It may not be obvious exactly what will happen when casting between certain types. For instance, the following should be - noted: - + noted. + </para> + <para> + When casting from a scalar or a string variable to an array, the + variable will become the first element of the array: + <informalexample> + <programlisting> +$var = 'ciao'; +$arr = (array) $var; +echo $arr[0]; // outputs 'ciao' + </programlisting> + </informalexample> + </para> + <para> + When casting from a scalar or a string variable to an object, the + variable will become an attribute of the object; the attribute + name will be 'scalar': + <informalexample> + <programlisting> +$var = 'ciao'; +$obj = (object) $var; +echo $obj-&gt;scalar; // outputs 'ciao' + </programlisting> + </informalexample> </para> + </sect2> </sect1>

« previous php.dev (#12590) next »