|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #78822 Returning from multiple function calls
Submitted: 2019-11-16 01:34 UTC Modified: 2019-11-17 11:54 UTC
From: mail-roboczy-dla-forow at wp dot pl Assigned:
Status: Suspended Package: *General Issues
PHP Version: Next Minor Version OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mail-roboczy-dla-forow at wp dot pl
New email:
PHP Version: OS:


 [2019-11-16 01:34 UTC] mail-roboczy-dla-forow at wp dot pl
function analyze($anyParameter)
   foreach($anyParameter as &$v)

function b(&$obj)
   foreach($obj as $line)
      $res=b(substr($line,3)); /* recurrent function */

function c(&$line)
      return 3;
      return 4;
   if($line=='unexpected data')
      [analyze] return false; /* return from previous calls 
                                 and return 'false' from 
                                 'analyze' function and 
                                 continue execution from
                                 next instruction after 
                                 last 'analyze' call. */
   return -1;

Test script:
No test script, the functionality will help faster return from multiple calls, for example analyzing jpeg, gif or odt files. It is the common situation that the analyzing function identyify unexpected data and the analysis must by broken due to nonsense data and returns error code. 

It is possible to write code without this enhancement but the code will be longer  and will contain additional conditions slowing execution of multiple nested calls. 

Expected result:
additional syntax 

[functionName] return result;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-16 01:35 UTC]
-Status: Open +Status: Feedback -Package: PHP Language Specification +Package: *General Issues
 [2019-11-16 01:35 UTC]
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.

 [2019-11-16 11:55 UTC] rowan dot collins at gmail dot com
It sounds like what you're looking for is exceptions. The main difference is that exceptions don't have to know where they will be caught, so they're a lot more flexible. In your example function c could throw an exception, and function analyze would catch it and continue to the next input item.
 [2019-11-16 17:36 UTC] mail-roboczy-dla-forow at wp dot pl
But... "try catch" will not slow execution of code? 
"Try catch throw" needs definition of subclass of Exception to catch only it.
 [2019-11-17 11:54 UTC]
Re performance: if in doubt, measure!  Also I suggest that you
reconsider the excessive usage of references; see

Re this feature request: this is certainly controversial, so would
require discussion on the internals mailing list[1].  Feel free to
forward the request to there.  For the time being, I'm suspending
this ticket.

[1] <>
 [2019-11-17 11:54 UTC]
-Status: Feedback +Status: Suspended
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Dec 03 14:01:27 2020 UTC