language/types/object.xml
e587d0655e426f97b3fcb431453da5030e743b23
...
...
@@ -11,7 +11,8 @@
11
11
to instantiate a class:
12
12
</para>
13
13

14
-
<informalexample>
14
+
<example>
15
+
<title>Object Construction</title>
15
16
<programlisting role="php">
16
17
<![CDATA[
17
18
<?php
...
...
@@ -28,7 +29,7 @@ $bar->do_foo();
28
29
?>
29
30
]]>
30
31
</programlisting>
31
-
</informalexample>
32
+
</example>
32
33

33
34
<simpara>
34
35
For a full discussion, see the
...
...
@@ -43,31 +44,35 @@ $bar->do_foo();
43
44
<para>
44
45
If an <type>object</type> is converted to an <type>object</type>, it is not
45
46
modified. If a value of any other type is converted to an
46
-
<type>object</type>, a new instance of the <literal>stdClass</literal>
47
+
<type>object</type>, a new instance of the <classname>stdClass</classname>
47
48
built-in class is created. If the value was &null;, the new instance will be
48
49
empty. An <type>array</type> converts to an <type>object</type> with properties
49
-
named by keys and corresponding values, with the exception of numeric keys which
50
-
will be inaccessible unless iterated.
50
+
named by keys and corresponding values. Note that in this case before PHP 7.2.0 numeric keys
51
+
have been inaccessible unless iterated.
51
52
</para>
52
53

53
-
<informalexample>
54
+
<example>
55
+
<title>Casting to an Object</title>
54
56
<programlisting role="php">
55
57
<![CDATA[
56
58
<?php
57
59
$obj = (object) array('1' => 'foo');
58
-
var_dump(isset($obj->{'1'})); // outputs 'bool(false)'
59
-
var_dump(key($obj)); // outputs 'int(1)'
60
+
var_dump(isset($obj->{'1'})); // outputs 'bool(true)'
61
+

62
+
// Deprecated as of PHP 8.1
63
+
var_dump(key($obj)); // outputs 'string(1) "1"'
60
64
?>
61
65
]]>
62
66
</programlisting>
63
-
</informalexample>
67
+
</example>
64
68

65
69
<para>
66
70
For any other value, a member variable named <literal>scalar</literal> will contain
67
71
the value.
68
72
</para>
69
73

70
-
<informalexample>
74
+
<example>
75
+
<title><literal>(object)</literal> cast</title>
71
76
<programlisting role="php">
72
77
<![CDATA[
73
78
<?php
...
...
@@ -76,7 +81,7 @@ echo $obj->scalar; // outputs 'ciao'
76
81
?>
77
82
]]>
78
83
</programlisting>
79
-
</informalexample>
84
+
</example>
80
85

81
86
</sect2>
82
87
</sect1>
83
88