|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21725 return behaviour differs between include and require
Submitted: 2003-01-18 07:12 UTC Modified: 2003-02-11 09:49 UTC
From: josh at chatgris dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.3.1-dev OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
9 + 19 = ?
Subscribe to this entry?

 [2003-01-18 07:12 UTC] josh at chatgris dot com
when a return is made out of an included file (using 
include), the value is properly returned.  However, using 
the require statement instead results in values not being 
preperly returned from a return statement in included 
This function currently exists in a class and works. 
function execQuery( &$sql, $result_status, $file, $line ) 
  	return include( dirname( __FILE__ 
)."/execQuery.php" ); 
This function DOES NOT WORK when I attempt the use the 
result it is not defined. 
function execQuery( &$sql, $result_status, $file, $line ) 
  	return require( dirname( __FILE__ 
)."/execQuery.php" ); 
This is the contents of the file it includes 
		$this->validateFileConstants( $file, 
$line, __FILE__, __LINE__ ); 
    if ( !is_string( $sql ) ) { 
      $this->{$this->log_func} ( "File: $file. Line: 
$line. \$sql is NOT a string. (%s, %d)",__FILE__, __LINE__ 
    if ( !is_int( $result_status ) ) { 
      $this->{$this->log_func} ( "File: $file. Line: 
$line. \$sql is NOT a string. (%s, %d)", __FILE__, 
__LINE__ ); 
    if ( $this->conn == NULL ) { 
    	$this->{$this->log_func} ( "File: $file. Line: 
$line. \$conn not open. (%s, %d)", __FILE__, __LINE__ ); 
    if ( pg_result_status( $rs = pg_query ( $this->conn, 
$sql ) ) !== $result_status ) { 
      /*pg_query returns false, can't use result_error.*/ 
      $this->{$this->log_func} ( "File: $file. Line: 
$line. Error executing. \"%s\" (%s, %d)" 
                              , pg_last_error(), __FILE__, 
__LINE__ ); 
    return $rs; 
This behavious is also inconsistent with tjhe document 
which reads that the onyl difference if a warning or Fatal 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-10 11:54 UTC]
Simple test case:



return 'foo';

Running test.php outputs:

string(3) "foo"

 [2003-02-11 09:49 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 04 11:01:26 2023 UTC