php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32657 return statements in includes from a method always return null
Submitted: 2005-04-10 18:44 UTC Modified: 2005-04-10 22:31 UTC
From: LoN_Kamikaze at gmx dot de Assigned:
Status: Not a bug Package: Output Control
PHP Version: 5.0.4 OS: WinXP SP2
Private report: No CVE-ID: None
 [2005-04-10 18:44 UTC] LoN_Kamikaze at gmx dot de
Description:
------------
As the PHP Documentation says:
"When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward."

From this I take that if an include occurs in a method, the included script should be able to use a return statement. Doing this terminates the method, but the returned value is always null.

Reproduce code:
---------------
index.php
<?php
class testReturn {
 public test() {
  include('test.php');
  return 'there has been no return statement';
 }
}
$test = new testReturn();
$test->test();
?>

test.php
<?php
return 'Test return statement.';
?>

Expected result:
----------------
Test return statement.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-10 18:52 UTC] LoN_Kamikaze at gmx dot de
Line 9 of the index.php reproduce code has of course to be
echo $test->test();
 [2005-04-10 20:29 UTC] johannes@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


 [2005-04-10 22:22 UTC] LoN_Kamikaze at gmx dot de
If it is not a bug, shouldn't return cause an error? It's a bug one way or another.
 [2005-04-10 22:31 UTC] johannes@php.net
You return from the included script not from    
testReturn::test(). Please ask further support   
questions in the support forums/lists...  
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 17:01:30 2025 UTC