reference/array/functions/array-fill.xml
ce882c196dce81bf6bd4d94af4fa4110ddc49ef4
...
...
@@ -37,8 +37,9 @@
37
37
If <parameter>start_index</parameter> is negative,
38
38
the first index of the returned array will be
39
39
<parameter>start_index</parameter> and the following
40
-
indices will start from zero
41
-
(see <link linkend="function.array-fill.example.basic">example</link>).
40
+
indices will start from zero prior to PHP 8.0.0;
41
+
as of PHP 8.0.0, negative keys are incremented normally
42
+
(see <link linkend="function.array-fill.example.negative-start-index">example</link>).
42
43
</para>
43
44
</listitem>
44
45
</varlistentry>
...
...
@@ -48,7 +49,7 @@
48
49
<listitem>
49
50
<para>
50
51
Number of elements to insert.
51
-
Must be greater than or equal to zero.
52
+
Must be greater than or equal to zero, and less than or equal to <literal>2147483647</literal>.
52
53
</para>
53
54
</listitem>
54
55
</varlistentry>
...
...
@@ -76,11 +77,35 @@
76
77
<refsect1 role="errors">
77
78
&reftitle.errors;
78
79
<para>
79
-
Throws a <constant>E_WARNING</constant> if <parameter>count</parameter> is
80
-
less than zero.
80
+
Throws a <classname>ValueError</classname> if <parameter>count</parameter> is
81
+
out of range.
81
82
</para>
82
83
</refsect1>
83
84

85
+
<refsect1 role="changelog">
86
+
&reftitle.changelog;
87
+
<informaltable>
88
+
<tgroup cols="2">
89
+
<thead>
90
+
<row>
91
+
<entry>&Version;</entry>
92
+
<entry>&Description;</entry>
93
+
</row>
94
+
</thead>
95
+
<tbody>
96
+
<row>
97
+
<entry>8.0.0</entry>
98
+
<entry>
99
+
<function>array_fill</function> now throws a <classname>ValueError</classname>
100
+
if <parameter>count</parameter> is out of range; previously <constant>E_WARNING</constant>
101
+
was raised, and the function returned &false;.
102
+
</entry>
103
+
</row>
104
+
</tbody>
105
+
</tgroup>
106
+
</informaltable>
107
+
</refsect1>
108
+

84
109
<refsect1 role="examples">
85
110
&reftitle.examples;
86
111
<para>
...
...
@@ -90,9 +115,7 @@
90
115
<![CDATA[
91
116
<?php
92
117
$a = array_fill(5, 6, 'banana');
93
-
$b = array_fill(-2, 4, 'pear');
94
118
print_r($a);
95
-
print_r($b);
96
119
?>
97
120
]]>
98
121
</programlisting>
...
...
@@ -108,6 +131,24 @@ Array
108
131
[9] => banana
109
132
[10] => banana
110
133
)
134
+
]]>
135
+
</screen>
136
+
</example>
137
+
</para>
138
+
<para>
139
+
<example xml:id="function.array-fill.example.negative-start-index">
140
+
<title><function>array_fill</function> example with a negative start index</title>
141
+
<programlisting role="php">
142
+
<![CDATA[
143
+
<?php
144
+
$a = array_fill(-2, 4, 'pear');
145
+
print_r($a);
146
+
?>
147
+
]]>
148
+
</programlisting>
149
+
&example.outputs.7;
150
+
<screen>
151
+
<![CDATA[
111
152
Array
112
153
(
113
154
[-2] => pear
...
...
@@ -117,8 +158,23 @@ Array
117
158
)
118
159
]]>
119
160
</screen>
161
+
&example.outputs.8;
162
+
<screen>
163
+
<![CDATA[
164
+
Array
165
+
(
166
+
[-2] => pear
167
+
[-1] => pear
168
+
[0] => pear
169
+
[1] => pear
170
+
)
171
+
]]>
172
+
</screen>
120
173
</example>
121
174
</para>
175
+
<para>
176
+
Note that index <literal>-1</literal> is not present prior to PHP 8.0.0.
177
+
</para>
122
178
</refsect1>
123
179

124
180
<refsect1 role="notes">
125
181