Added a note about array to object casting

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@335216 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Tjerk Anne Meesters 2014-11-25 23:25:55 +00:00
parent 60e8e031cf
commit 2927fdd599

View file

@ -45,9 +45,26 @@ $bar->do_foo();
modified. If a value of any other type is converted to an
<type>object</type>, a new instance of the <literal>stdClass</literal>
built-in class is created. If the value was &null;, the new instance will be
empty. <type>Array</type>s convert to an <type>object</type> with properties
named by keys, and corresponding values. For any other value, a member
variable named <literal>scalar</literal> will contain the value.
empty. An <type>array</type> converts to an <type>object</type> with properties
named by keys and corresponding values, with the exception of numeric keys which
will be inaccessible unless iterated.
</para>
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
$obj = (object) array('1' => 'foo');
var_dump(isset($obj->{'1'})); // outputs 'bool(false)'
var_dump(key($obj)); // outputs 'int(1)'
?>
]]>
</programlisting>
</informalexample>
<para>
For any other value, a member variable named <literal>scalar</literal> will contain
the value.
</para>
<informalexample>