reference/filesystem/functions/file-get-contents.xml
ea62fb83196997032641b50fe44420305466195e
...
...
@@ -9,18 +9,18 @@
9
9
<refsect1 role="description">
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
-
<type>string</type><methodname>file_get_contents</methodname>
12
+
<type class="union"><type>string</type><type>false</type></type><methodname>file_get_contents</methodname>
13
13
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
14
14
<methodparam choice="opt"><type>bool</type><parameter>use_include_path</parameter><initializer>&false;</initializer></methodparam>
15
-
<methodparam choice="opt"><type>resource</type><parameter>context</parameter></methodparam>
15
+
<methodparam choice="opt"><type class="union"><type>resource</type><type>null</type></type><parameter>context</parameter><initializer>&null;</initializer></methodparam>
16
16
<methodparam choice="opt"><type>int</type><parameter>offset</parameter><initializer>0</initializer></methodparam>
17
-
<methodparam choice="opt"><type>int</type><parameter>maxlen</parameter></methodparam>
17
+
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>length</parameter><initializer>&null;</initializer></methodparam>
18
18
</methodsynopsis>
19
19
<para>
20
20
This function is similar to <function>file</function>, except that
21
21
<function>file_get_contents</function> returns the file in a
22
22
<type>string</type>, starting at the specified <parameter>offset</parameter>
23
-
up to <parameter>maxlen</parameter> bytes. On failure,
23
+
up to <parameter>length</parameter> bytes. On failure,
24
24
<function>file_get_contents</function> will return &false;.
25
25
</para>
26
26
<para>
...
...
@@ -53,11 +53,11 @@
53
53
<listitem>
54
54
<note>
55
55
<para>
56
-
As of PHP 5 the <constant>FILE_USE_INCLUDE_PATH</constant> constant can be used
56
+
The <constant>FILE_USE_INCLUDE_PATH</constant> constant can be used
57
57
to trigger <link linkend="ini.include-path">include path</link>
58
58
search.
59
59
This is not possible if <link
60
-
linkend="functions.arguments.type-declaration.strict">strict typing</link>
60
+
linkend="language.types.declarations.strict">strict typing</link>
61
61
is enabled, since <constant>FILE_USE_INCLUDE_PATH</constant> is an
62
62
<type>int</type>. Use &true; instead.
63
63
</para>
...
...
@@ -89,7 +89,7 @@
89
89
</listitem>
90
90
</varlistentry>
91
91
<varlistentry>
92
-
<term><parameter>maxlen</parameter></term>
92
+
<term><parameter>length</parameter></term>
93
93
<listitem>
94
94
<para>
95
95
Maximum length of data read. The default is to read until end
...
...
@@ -113,9 +113,44 @@
113
113
<refsect1 role="errors">
114
114
&reftitle.errors;
115
115
<para>
116
-
An <constant>E_WARNING</constant> level error is generated if <parameter>filename</parameter> cannot be found, <parameter>maxlength</parameter>
116
+
An <constant>E_WARNING</constant> level error is generated if <parameter>filename</parameter> cannot be found, <parameter>length</parameter>
117
117
is less than zero, or if seeking to the specified <parameter>offset</parameter> in the stream fails.
118
118
</para>
119
+
<para>
120
+
When <function>file_get_contents</function> is called on a directory,
121
+
an <constant>E_WARNING</constant> level error is generated on Windows,
122
+
and as of PHP 7.4 on other operating systems as well.
123
+
</para>
124
+
</refsect1>
125
+

126
+
<refsect1 role="changelog">
127
+
&reftitle.changelog;
128
+
<para>
129
+
<informaltable>
130
+
<tgroup cols="2">
131
+
<thead>
132
+
<row>
133
+
<entry>&Version;</entry>
134
+
<entry>&Description;</entry>
135
+
</row>
136
+
</thead>
137
+
<tbody>
138
+
<row>
139
+
<entry>8.0.0</entry>
140
+
<entry>
141
+
<parameter>length</parameter> is nullable now.
142
+
</entry>
143
+
</row>
144
+
<row>
145
+
<entry>7.1.0</entry>
146
+
<entry>
147
+
Support for negative <parameter>offset</parameter>s has been added.
148
+
</entry>
149
+
</row>
150
+
</tbody>
151
+
</tgroup>
152
+
</informaltable>
153
+
</para>
119
154
</refsect1>
120
155

121
156
<refsect1 role="examples">
...
...
@@ -137,9 +172,9 @@ echo $homepage;
137
172
<programlisting role="php">
138
173
<![CDATA[
139
174
<?php
140
-
// <= PHP 5
175
+
// If strict types are enabled i.e. declare(strict_types=1);
141
176
$file = file_get_contents('./people.txt', true);
142
-
// > PHP 5
177
+
// Otherwise
143
178
$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);
144
179
?>
145
180
]]>
...
...
@@ -188,37 +223,6 @@ $file = file_get_contents('http://www.example.com/', false, $context);
188
223
</para>
189
224
</refsect1>
190
225

191
-
<refsect1 role="changelog">
192
-
&reftitle.changelog;
193
-
<para>
194
-
<informaltable>
195
-
<tgroup cols="2">
196
-
<thead>
197
-
<row>
198
-
<entry>&Version;</entry>
199
-
<entry>&Description;</entry>
200
-
</row>
201
-
</thead>
202
-
<tbody>
203
-
<row>
204
-
<entry>7.1.0</entry>
205
-
<entry>
206
-
Support for negative <parameter>offset</parameter>s has been added.
207
-
</entry>
208
-
</row>
209
-
<row>
210
-
<entry>5.1.0</entry>
211
-
<entry>
212
-
Added the <parameter>offset</parameter> and
213
-
<parameter>maxlen</parameter> parameters.
214
-
</entry>
215
-
</row>
216
-
</tbody>
217
-
</tgroup>
218
-
</informaltable>
219
-
</para>
220
-
</refsect1>
221
-

222
226
<refsect1 role="notes">
223
227
&reftitle.notes;
224
228
&note.bin-safe;
225
229