note 127107 added to function.require-once
| From: | bobray99 at softville dot com | Date: | Tue, 17 May 2022 05:52:33 +0000 |
| Subject: | note 127107 added to function.require-once | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218478@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 = require_once('fiddle2.php');
echo "\n" . $s;
$s = require_once('fiddle2.php');
echo "\n" . $s;
/* output
Some String
1
*/
The second time require_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.require-once.php
Edit -- https://main.php.net/note/edit/127107
Del: integrated -- https://main.php.net/note/delete/127107/integrated
Del: useless -- https://main.php.net/note/delete/127107/useless
Del: bad code -- https://main.php.net/note/delete/127107/bad+code
Del: spam -- https://main.php.net/note/delete/127107/spam
Del: non-english -- https://main.php.net/note/delete/127107/non-english
Del: in docs -- https://main.php.net/note/delete/127107/in+docs
Del: other reasons-- https://main.php.net/note/delete/127107
Reject -- https://main.php.net/note/reject/127107
Search -- https://main.php.net/manage/user-notes.php