#32657 [Bgs]: return statements in includes from a method always return null

From: Date: Sun, 10 Apr 2005 20:31:33 +0000
Subject: #32657 [Bgs]: return statements in includes from a method always return null
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-76607@lists.php.net to get a copy of this message
ID: 32657 Updated by: johannes@php.net Reported By: LoN_Kamikaze at gmx dot de Status: Bogus Bug Type: Output Control Operating System: WinXP SP2 PHP Version: 5.0.4 New Comment: You return from the included script not from testReturn::test(). Please ask further support questions in the support forums/lists... Previous Comments: ------------------------------------------------------------------------ [2005-04-10 22:22:39] 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 20:29:04] 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 18:52:15] 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 18:44:10] 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=32657&edit=1

« previous php.bugs (#76607) next »