New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assign-by-reference false positive for call-time pass-by-reference sniff #68
Comments
Isn't this a Fatal Error since PHP 5.4? |
See also the PHP reference.
|
In fact this code ends up with Fatal Error: <?php
function testMe(&$param) {
}
$var = 1;
testMe(&$var); |
Yes, that code gives a fatal. But that's not the code I'm pointing out in this issue. There are three kinds of "by reference" in PHP: pass-by-reference, assign-by-reference, and return-by-reference. The sniff handles only pass-by-reference, gives a false positive for assign-by-reference, and may also give a false positive for return-by-reference (I haven't checked that scenario). |
Something like this will throw a PHP Strict Standard error in 5.4+: $array = array('a' => 1, 'b' => 2, 'c' => 3);
$value = array_shift(array_values($array)); // Only variables should be passed by reference
echo $value; It would be great if PHPCompatibility could also identify this scenario. |
I'm getting false positives from this for a few popular WordPress plugins like Jetpack. The code looks like this:
You can find the code here: https://github.com/Automattic/jetpack/blob/master/_inc/lib/markdown/extra.php#L2505 And the logs here:
How difficult would this be to resolve? |
This issue was resolved a few weeks ago. Anyone still having issues with it ? |
No new information was received, so closing for now. |
I just got another report of this:
The code looks like this:
It's actually assigning the value, then passing it. Full report here: https://wordpress.org/support/topic/false-positive-comet-cache/ |
Assignment by reference is only deprecated for object construction since PHP 5.3. Consider:
However, this scenario isn't covered by
Tests/sniff-examples/call_time_pass_by_reference.php
and produces a false positive for code such as the above.The text was updated successfully, but these errors were encountered: