php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #25108 include doesn't return the right value
Submitted: 2003-08-16 09:32 UTC Modified: 2004-07-27 22:13 UTC
From: mailling at gmx dot co dot uk Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4CVS-2003-08-16 (stable) OS: Windows 2000
Private report: No CVE-ID: None
 [2003-08-16 09:32 UTC] mailling at gmx dot co dot uk
Description:
------------
It seems that the variable returned by a correct insert changed from the last PHP version. Is it a change in the behavior or a bug?
If I include a file and everything is fine, it returns NULL, but it should return 1 or true (it does true, but the documentation says 1)

Reproduce code:
---------------
// The file base.inc.php exists, base.inc.php2 doesn't

$a = require_once(PROJECT_BASE . '/include/base.inc.php');
$b = require_once(PROJECT_BASE . '/include/base.inc.php');
$c = include_once(PROJECT_BASE . '/include/base.inc.php2');
var_dump($a); // return NULL
var_dump($b); // return true
var_dump($c); // return false

Expected result:
----------------
true (or 1?)
true (or 1?)
false

Actual result:
--------------
NULL
true
false

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-16 10:34 UTC] derick@php.net
Having a look at this...
 [2003-08-16 10:45 UTC] derick@php.net
Hmm, this works for me and it returns the correct result:

int(1)
bool(true)
bool(false)

It's correct because:
if there is no return statement in your include file, an implicit "return 1;" is added. The second require_once does not include anything, so the return 1 is never executed, but instead the return value returns the success of the return_once call. (It was a success because the file could be included the first time). The include_once() fails because the file exists, and thus include_once() returns bool(false).

I think you have a "return;" inside your base.inc.php file (or something similar like a die()) and thus the first require_once returns "NULL" (as you're overwriting the default implicit "return 1;".

This should definitely be added to the docs though, as they don't even talk about return values from include/require functions. (Atleast I couldn't find it).

Derick
 [2004-07-27 22:13 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

include:
"If there is no return statement inside an included file, implicit 'return 1;' is added at the end of the file. If the file can't be included, false is returned."

include_once, require_once:
"Return values are the same as with include(). If the file
was already included, this function returns true."

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Sep 08 21:00:01 2025 UTC