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

Bug #17860 isReference function fails with references in array
Submitted: 2010-09-10 19:18 UTC
From: ljmaskey Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.2.2)
PHP Version: 5.2.9 OS: Windows XP
Roadmaps: (Not assigned)    
Subscription  


 [2010-09-10 19:18 UTC] ljmaskey (Lincoln Maskey)
Description: ------------ When tokenising an array construct whose parameters are references, the isReference function in File.php incorrectly returns false. Test script: --------------- <?php error_reporting(0); require_once('PHP/CodeSniffer.php'); $file = new PHP_CodeSniffer_File(); $file->start( '<?php $a = "a"; $b = array(&$a); echo $a; $b[0] = "A"; echo $a; ?>' ); echo 'Looking at tokens 14 and 15: ' . $file->getTokensAsString(14, 2) . "\n"; echo 'Is token 14 a reference? ' . ($file->isReference(14) ? 'Yes' : 'No') . "\n"; ?> Expected result: ---------------- Expected isReference to return true for the token that is the ampersand before the $a variable on line 9. Actual result: -------------- At the moment, it returns false. This can be resolved by changing line 2147 (in v1.2.2) from: if ($owner['code'] === T_FUNCTION) { to: if (in_array($owner['code'], array(T_FUNCTION, T_ARRAY), true)) {

Comments

 [2010-11-19 09:19 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Closed -Assigned To: +Assigned To: squiz
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.