Req #78822 [Com]: Returning from multiple function calls
| From: | mail-roboczy-dla-forow at wp dot pl | Date: | Sat, 16 Nov 2019 17:36:37 +0000 |
| Subject: | Req #78822 [Com]: Returning from multiple function calls | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-223744@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78822&edit=1
ID: 78822
Comment by: mail-roboczy-dla-forow at wp dot pl
Reported by: mail-roboczy-dla-forow at wp dot pl
Summary: Returning from multiple function calls
Status: Feedback
Type: Feature/Change Request
Package: *General Issues
Operating System: All
PHP Version: Next Minor Version
Block user comment: N
Private report: N
New Comment:
But... "try catch" will not slow execution of code?
"Try catch throw" needs definition of subclass of Exception to catch only it.
Previous Comments:
------------------------------------------------------------------------
[2019-11-16 11:55:57] 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 01:35:52] requinix@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php
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 01:34:41] mail-roboczy-dla-forow at wp dot pl
Description:
------------
function analyze($anyParameter)
{
foreach($anyParameter as &$v)
b($v);
}
function b(&$obj)
{
foreach($obj as $line)
{
$res=c($line);
}
if(...)
{
...
$res=b(substr($line,3)); /* recurrent function */
...
}
...
}
function c(&$line)
{
if($line=='1')
return 3;
if($line=='2')
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;
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78822&edit=1