Hi,
During the PHP Compatibility check with PHP CodeSniffer the coding standard throws an error caused by ctools_api.common.inc line 549:
$data = call_user_func_array(__FUNCTION__, [
[$child => $element[$child]],
$form_state,
$conf_child,
$plugin,
empty($element['#tree']),
]);
And 776:
call_user_func_array(__FUNCTION__, [$element[$child], $form_state]);
The error is the same for both cases:
Using a call-time pass-by-reference is deprecated since PHP 5.3 and prohibited since PHP 5.4 (PHPCompatibility.PHP.ForbiddenCallTimePassByReference.NotAllowed)
General info about passing by reference and the deprecation.
This is required to pass the coding standards check without errors on several projects we're working on.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | interdiff-2984571-10-14.txt | 21.15 KB | br0ken |
| #14 | 2984571-14.patch | 24.52 KB | br0ken |
Comments
Comment #2
railgun commentedA patch with the fix.
Comment #3
br0kenI think this small patch is the complete destroyer of module's functionality.
What this code prints for you?
And then replace
call_user_func_array('myfunc', [$params]);by thecall_user_func_array('myfunc', [&$params]);.Also, did you get a real issue with this? I mean real and not statically generated by some syntax analyzers.
Do not hesitate to reopen this issue if I'm not correct or you have a real issue though.
Comment #4
bahbka commentedI agree with #3 this patch breaks things. But I don't know why this functionality works on PHP 7 and not throwing any warnings. By default it should return FALSE and produce many warnings. But one general question here, why call_user_func_array was used here instead of direct call to the function itself: you always know what should be called?
Comment #5
bahbka commentedComment #6
bahbka commented@broken I'm talking about this approach, please take a look at attached patch. In my opinion it will simplify code a bit and it will resolve issue that was originally described in this ticket.
Comment #7
br0ken@BAHbKA, the in-use approach is correct because both of thin moments are controlled: function definition and its call. The function defined with the parameter that's handled as a reference. The call of the function via
call_user_func_array()simply does what the called function expects - passes value by reference.Yet another example:
If you change the definition from
call_time_pass_by_reference_CONTROLLED(array &$params): voidtocall_time_pass_by_reference_CONTROLLED(array $params): voidthen it'll become uncontolled and you get the warnings/incorrect behavior.I'm definitely not against the patch you've proposed in a case the https://github.com/wimg/PHPCompatibility has no tags like @codingStandardsIgnoreStart.
Comment #8
br0kenAh, wait, I fooled. The https://github.com/wimg/PHPCompatibility is a coding standard extension for PHPCS, therefore we can use proposed tags.
Comment #9
br0kenMy proposition.
Comment #10
br0kenFix the incorrect sequence of comments.
Comment #11
bahbka commentedThanks @broken! Initially wanted todo the same but what stopped me is lack of knowledge why it is working.
Comment #12
br0ken@BAHbKA, please let me know whether #10 works for you. For now I have no ability to run
phpcs.Comment #13
br0kenWell, I managed to run the check and here is what I got:
Without #10 the result is:
Therefore, I'm ready to commit latest patch if you confirm #10 fixes the issue for you.
Comment #14
br0kenThe final patch that sets up PHPCS (Drupal + PHPCompatibility) checks and PHPUnit tests for the project using Travis CI (PHP 5.6, 7.0 and 7.1 for now).
The latest build can be checked here: https://travis-ci.org/BR0kEN-/ctools_api/jobs/403685217
Comment #16
br0kenComment #17
br0kenThe new release with all the fixes has been bumped out. Check it out - https://www.drupal.org/project/ctools_api/releases/7.x-1.2.
Thanks everyone!