Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.4.2

Bug #18835 Unreachable errors of inline returns of closure functions
Submitted: 2011-09-15 18:03 UTC
From: woellchen Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.0)
PHP Version: 5.3.1 OS: Ubuntu 11.04 (Natty Narwhal)
Roadmaps: (Not assigned)    
Subscription  


 [2011-09-15 18:03 UTC] woellchen (Patrick Schmidt)
Description: ------------ The CodeSniffer detects return statements in a closure function which is in turn returned directly as a warning. Our current workaround is to save the closure function in a variable, returning this variable afterwards. Test script: --------------- <?php // produces a warning return uksort($array, function() { return mt_rand(-1, 1); }); // produces no warning $return = uksort($array, function() { return mt_rand(-1, 1); }); return $return; Expected result: ---------------- No errors or warnings. Actual result: -------------- WARNING | Code after RETURN statement cannot be executed | (Squiz.PHP.NonExecutableCode.Unreachable)

Comments

 [2011-09-15 18:10 UTC] woellchen (Patrick Schmidt)
 [2011-09-18 13:01 UTC] doconnor (Daniel O'Connor)
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: squiz
Thanks for the patch Patrick! There's a bit of tabs vs whitespace that should be fixed prior to it merging; but otherwise it looks good from a casual glance
 [2011-09-19 08:56 UTC] squiz (Greg Sherwood)
-Status: Analyzed +Status: Closed
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. Thanks a lot for the patch.