Req #78822 [Fbk->Sus]: Returning from multiple function calls

From: Date: Sun, 17 Nov 2019 11:54:25 +0000
Subject: Req #78822 [Fbk->Sus]: Returning from multiple function calls
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223755@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 Updated by: cmb@php.net Reported by: mail-roboczy-dla-forow at wp dot pl Summary: Returning from multiple function calls -Status: Feedback +Status: Suspended Type: Feature/Change Request Package: *General Issues Operating System: All PHP Version: Next Minor Version Block user comment: N Private report: N New Comment: Re performance: if in doubt, measure! Also I suggest that you reconsider the excessive usage of references; see <http://schlueters.de/blog/archives/180-References-Still-bad-in-PHP-7.html>. 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] <https://www.php.net/mailing-lists.php> Previous Comments: ------------------------------------------------------------------------ [2019-11-16 17:36:37] 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-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

« previous php.bugs (#223755) next »