reference/array/functions/array-fill.xml
ce882c196dce81bf6bd4d94af4fa4110ddc49ef4
...
...
@@ -11,12 +11,12 @@
11
11
<methodsynopsis>
12
12
<type>array</type><methodname>array_fill</methodname>
13
13
<methodparam><type>int</type><parameter>start_index</parameter></methodparam>
14
-
<methodparam><type>int</type><parameter>num</parameter></methodparam>
14
+
<methodparam><type>int</type><parameter>count</parameter></methodparam>
15
15
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
16
16
</methodsynopsis>
17
17
<para>
18
18
Fills an array with
19
-
<parameter>num</parameter> entries of the value of the
19
+
<parameter>count</parameter> entries of the value of the
20
20
<parameter>value</parameter> parameter, keys starting at the
21
21
<parameter>start_index</parameter> parameter.
22
22
</para>
...
...
@@ -37,18 +37,19 @@
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>
45
46

46
47
<varlistentry>
47
-
<term><parameter>num</parameter></term>
48
+
<term><parameter>count</parameter></term>
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,34 +77,33 @@
76
77
<refsect1 role="errors">
77
78
&reftitle.errors;
78
79
<para>
79
-
Throws a <constant>E_WARNING</constant> if <parameter>num</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

84
85
<refsect1 role="changelog">
85
86
&reftitle.changelog;
86
-
<para>
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>5.6.0</entry>
98
-
<entry>
99
-
<parameter>num</parameter> may now be zero. Previously,
100
-
<parameter>num</parameter> was required to be greater than zero.
101
-
</entry>
102
-
</row>
103
-
</tbody>
104
-
</tgroup>
105
-
</informaltable>
106
-
</para>
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
107
</refsect1>
108
108

109
109
<refsect1 role="examples">
...
...
@@ -115,9 +115,7 @@
115
115
<![CDATA[
116
116
<?php
117
117
$a = array_fill(5, 6, 'banana');
118
-
$b = array_fill(-2, 4, 'pear');
119
118
print_r($a);
120
-
print_r($b);
121
119
?>
122
120
]]>
123
121
</programlisting>
...
...
@@ -133,6 +131,24 @@ Array
133
131
[9] => banana
134
132
[10] => banana
135
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[
136
152
Array
137
153
(
138
154
[-2] => pear
...
...
@@ -142,8 +158,23 @@ Array
142
158
)
143
159
]]>
144
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>
145
173
</example>
146
174
</para>
175
+
<para>
176
+
Note that index <literal>-1</literal> is not present prior to PHP 8.0.0.
177
+
</para>
147
178
</refsect1>
148
179

149
180
<refsect1 role="notes">
...
...
@@ -166,7 +197,6 @@ Array
166
197
</refsect1>
167
198

168
199
</refentry>
169
-

170
200
<!-- Keep this comment at the end of the file
171
201
Local variables:
172
202
mode: sgml
173
203