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

Bug #18465 "self::" does not work in lambda functions
Submitted: 2011-04-20 18:40 UTC
From: konafets Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.0)
PHP Version: 5.3.5 OS: Mac OSX
Roadmaps: (Not assigned)    
Subscription  


 [2011-04-20 18:40 UTC] konafets (Stefano Kowalke)
Description: ------------ Squiz.Classes.SelfMemberReference report a violation if you use the classname to reference to static function in closure. Test script: --------------- https://review.typo3.org/#patch,unified,1647,5,t3lib/utility/class.t3lib_utility_array.php at line 82 Expected result: ---------------- The sniff should not report a violation. Actual result: -------------- Must use "self::" for local static member reference

Comments

 [2011-04-26 19:36 UTC] konafets (Stefano Kowalke)
-Operating System: +Operating System: Mac OSX
 [2011-04-28 04:53 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Feedback -Assigned To: +Assigned To: squiz
Your test script URL requires a username and password and I can't find that file in the typo3 repo. Can you please post a short sample of code to replicate the issue so I know I'm fixing the right problem.
 [2011-04-28 13:19 UTC] konafets (Stefano Kowalke)
<?php /*************************************************************** * Copyright notice * * (c) 2011 Susanne Moog <typo3@susanne-moog.de> * All rights reserved * * This script is part of the TYPO3 project. The TYPO3 project is * free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * The GNU General Public License can be found at * http://www.gnu.org/copyleft/gpl.html. * A copy is found in the textfile GPL.txt and important notices to the license * from the author is found in LICENSE.txt distributed with these scripts. * * * This script is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ /** * Class with helper functions for array handling * * @author Susanne Moog <typo3@susanne-moog.de> * @package TYPO3 * @subpackage t3lib */ final class t3lib_utility_Array { /** * Reduce an array by a search value and keep the array structure. * * Comparison is type strict: * - For a given needle of type string, integer, array or boolean, * value and value type must match to occur in result array * - For a given object, a object within the array must be a reference to * the same object to match (not just different instance of same class) * * Example: * - Needle: 'findMe' * - Given array: * array( * 'foo' => 'noMatch', * 'bar' => 'findMe', * 'foobar => array( * 'foo' => 'findMe', * ), * ); * - Result: * array( * 'bar' => 'findMe', * 'foobar' => array( * 'foo' => findMe', * ), * ); * * See the unit tests for more examples and expected behaviour * * @static * @param mixed $needle The value to search for * @param array $haystack The array in which to search * @return array $haystack array reduced matching $needle values */ public static function filterByValueRecursive($needle = '', array $haystack = array()) { $resultArray = array(); // Define a lambda function to be applied to all members of this array dimension // Call recursive if current value is of type array // Write to $resultArray (by reference!) if types and value match $callback = function(&$value, $key) use ($needle, &$resultArray) { if ($value === $needle) { $resultArray[$key] = $value; } elseif (is_array($value)) { // self does not work in lambda functions, use t3lib_utility_Array for recursion $subArrayMatches = t3lib_utility_Array::filterByValueRecursive($needle, $value, $array[$key]); if (count($subArrayMatches) > 0) { $resultArray[$key] = $subArrayMatches; } } }; // array_walk() is not affected by the internal pointers, no need to reset array_walk($haystack, $callback); // Pointers to result array are reset internally return $resultArray; } } ?>
 [2011-05-02 10:20 UTC] squiz (Greg Sherwood)
-Status: Feedback +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.