FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=18835&edit=1

ID: 18835
Updated by: daniel.oconnor@gmail.com
Reported By: patrick dot schmidt at innogames dot de
Summary: Unreachable errors of inline returns of closure
functions
-Status: Open
+Status: Analyzed
Type: Bug
Package: PHP_CodeSniffer
Operating System: Ubuntu 11.04 (Natty Narwhal)
Package Version: 1.3.0
PHP Version: 5.3.1
-Assigned To:
+Assigned To: squiz
Roadmap Versions:
New Comment:

-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


Previous Comments:
------------------------------------------------------------------------

[2011-09-15 14:10:07] woellchen

Added #patch
bug:18835;patch:fix-wrong-unreachable-warning;revision:1316092206;.

------------------------------------------------------------------------

[2011-09-15 14:03:10] woellchen

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)
------------------------------------------------------------------------

Search Discussions

  • Gsherwood at Sep 19, 2011 at 2:55 am
    Edit report at http://pear.php.net/bugs/bug.php?id=18835&edit=1

    ID: 18835
    Updated by: gsherwood@squiz.net
    Reported By: patrick dot schmidt at innogames dot de
    Summary: Unreachable errors of inline returns of closure
    functions
    -Status: Analyzed
    +Status: Closed
    Type: Bug
    Package: PHP_CodeSniffer
    Operating System: Ubuntu 11.04 (Natty Narwhal)
    Package Version: 1.3.0
    PHP Version: 5.3.1
    Assigned To: squiz
    Roadmap Versions:
    New Comment:

    -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.


    Previous Comments:
    ------------------------------------------------------------------------

    [2011-09-18 09:01:37] doconnor

    -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-15 14:10:07] woellchen

    Added #patch
    bug:18835;patch:fix-wrong-unreachable-warning;revision:1316092206;.

    ------------------------------------------------------------------------

    [2011-09-15 14:03:10] woellchen

    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)
    ------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedSep 18, '11 at 7:00a
activeSep 19, '11 at 2:55a
posts2
users2
websitepear.php.net

2 users in discussion

Daniel Oconnor: 1 post Gsherwood: 1 post

People

Translate

site design / logo © 2022 Grokbase