note 127106 added to function.include-once
| From: | bobray99 at gmail dot com | Date: | Tue, 17 May 2022 05:49:26 +0000 |
| Subject: | note 127106 added to function.include-once | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218477@lists.php.net to get a copy of this message | ||
Be careful when using include_once and require_once for files that return a value:
fiddle2.php
<?php
return "Some String";
fiddle.php
<?php
$s = include_once('fiddle2.php');
echo "\n" . $s;
$s = include_once('fiddle2.php');
echo "\n" . $s;
/* output
Some String
1
*/
The second time include_once occurs, it returns 1 because the file has already been included.
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.47 (proxied: 2601:448:4200:1e7a:980a:7e5c:d999:f6e4)
----
Manual Page -- https://php.net/manual/en/function.include-once.php
Edit -- https://main.php.net/note/edit/127106
Del: integrated -- https://main.php.net/note/delete/127106/integrated
Del: useless -- https://main.php.net/note/delete/127106/useless
Del: bad code -- https://main.php.net/note/delete/127106/bad+code
Del: spam -- https://main.php.net/note/delete/127106/spam
Del: non-english -- https://main.php.net/note/delete/127106/non-english
Del: in docs -- https://main.php.net/note/delete/127106/in+docs
Del: other reasons-- https://main.php.net/note/delete/127106
Reject -- https://main.php.net/note/reject/127106
Search -- https://main.php.net/manage/user-notes.php