PHPCompatibility Code
PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
Explanation
Since PHP7.0 func_get_arg()
, func_get_args()
, debug_backtrace()
and exception backtraces have started reporting the current value of a parameter. When analysing your files, PHPCompatibility might not be able to determine if a parameter has been modified. To avoid missing cases where the value would have changed, all occurrences where a parameter is touched will be reported for manual inspection.
Recommendation
Manually inspect warnings. Fix problematic usages. Use phpcs:ignore
for the remaining false positives.
Example That Requires Fixing
function myFunction($email) {
$email = trim($email);
saveEmail($email);
return func_get_arg(0);
}
If the intent was to return the original value of $email
that was passed to the function, then you will need to fix the logic:
function myFunction($email) {
$newEmail = trim($email);
saveEmail($newEmail);
return func_get_arg(0);
}
What we did here is avoid overriding the value of $email
, so that it would still be possible to return the original value, maintaining the intended behavior of the code. We could also take the opportunity to get rid of func_get_arg
and return $email
directly, as the use of func_get_arg
is not necessary in this context.
Example That Should Be Ignored
function myFunction($name) {
log($name);
debug_backtrace();
}
There is nothing to fix here, yet it will still be reported as a warning by PHPCompatibility.
The following comment is an annotation allowing you to ignore a line or a specific sniff. Here we are specifying that we want to ignore the sniff by its name:
// phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
function myFunction($name) {
log($name);
debug_backtrace();
}
Migration Services
Increase security and cut risk by simplifying PHP application upgrades and migrations.
Get Long-Term Support With ZendPHP
Stay secure and compliant while migrating on your schedule with Zend PHP LTS.