php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37030 No return value from functions where code is included/required
Submitted: 2006-04-10 13:10 UTC Modified: 2006-04-10 14:05 UTC
From: stevenmoss at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.2 OS: Ubuntu 6.06
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: stevenmoss at gmail dot com
New email:
PHP Version: OS:

 

 [2006-04-10 13:10 UTC] stevenmoss at gmail dot com
Description:
------------
This bug was first reported (coincidentally) exactly one year ago as bug #32657 in Version 5.0.4, it was deemed bogus.  I believe that judgement was in error.

Reproduce code:
---------------
"Test.php"
<?php
Class TestObject {
   function ReturnTest() {
      require("ReturnTest.php");
   }
}
$oTest = New TestObject();
Echo $oTest->ReturnTest();
?>

"ReturnTest.php"
<?php
return "Test";
?>

Expected result:
----------------
"Test" should be output

Actual result:
--------------
No output

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-10 13:12 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2006-04-10 13:47 UTC] stevenmoss at gmail dot com
Thankyou for the swift response.

I must say I'm bewildered if this is the intended behaviour of PHP.  Why would it be ok for PHP to treat all the code within an included file as though it were within the including file EXCEPT for return values?  The return statement DOES execute (I have other examples which prove this), why then is it logical that it should not also return the value assigned to it?

This is very important for me because I have large objects with many functions which are difficult to manage unless split over many files.  This behaviour would seem to make it impossible for me to do so.

P.S. I have read the relevant documentation for program structure and the behaviour of include/require etc. before I submitted the bug report and it seems to back me up.

Thanks,
S
 [2006-04-10 13:50 UTC] tony2001@php.net
http://php.net/include

Handling Returns: It is possible to execute a return() statement inside an included file in order to terminate processing in that file and return to the script which called it. Also, it's possible to return values from included files. 

Try <?php echo require("ReturnTest.php"); ?>, you'll see what's this all about.
 [2006-04-10 14:05 UTC] stevenmoss at gmail dot com
Well that's just crazy, but thanks, I can solve my problem adequately with this amendment:

function ReturnTest() {
   return ( require("ReturnTest.php") );
}


(Just in case someone else thinks they're going to re-submit this bug)

S
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 10 12:01:33 2025 UTC