This is a direct copy of benjifisher's D8 issue #1863388: syntax error in update_manager_update_form(). The issue in D8 is revolved by moving to the new form interface, however the problem is also in D7.
The function declaration is
function update_manager_update_form($form, $form_state = array(), $context) {
If the second argument has a default value, then the third argument is supposed to have one, too.
I am not sure of the correct fix: give $context a default value, remove the default value from $form_state, or remove the third argument entirely (and maybe also the default value). AFAICT, $context is not referred to anywhere in the code. I did not see func_get_args() either, but maybe I overlooked something.
Comments
Comment #1
joyceg commentedComment #2
joyceg commentedComment #3
joyceg commentedComment #5
joyceg commentedCan someone help me with this issue?
Comment #6
prabhurajn654 commentedComment #7
prabhurajn654 commentedI think $context is not being used anywhere in this hook, so just removed unusmeter
Comment #8
prabhurajn654 commentedComment #9
lhuria94 commentedComment #10
lhuria94 commentedNot able to reproduce the issue.
Comment #11
hgoto commented$contextis not used at a glance. But thisupdate_manager_update_form()is a form function and passed todrupal_get_form(). Please seeupdate_menu()and you'll find$contextis used. So the proper approach is #2, I believe. I just reroll it.But I'm not sure this is a bug...
Comment #12
fabianx commented- https://3v4l.org/K38Xm
shows that it is an error in PHP 7.1 if just one argument is passed, but a warning in all others.
- https://3v4l.org/DH1q2
shows that the syntax is indeed valid.
So I think we could remove the "$form_state = array()", but changing $form_state to be a reference feels wrong as its not required.
Comment #13
hgoto commented@Fabianx, thank you for the review.
I see. I investigated the point to know we should keep
$form_stateas a value or change to a reference.In form building process, Drupal system calls
drupal_get_form()first. Then,drupal_get_form()callsdrupal_build_form()anddrupal_build_form()callsdrupal_retrieve_form().drupal_get_form():
drupal_build_form():
drupal_retrieve_form():
Then, the function
update_manager_update_form()is invoked in the line$form = call_user_func_array(isset($callback) ? $callback : $form_id, $args);indrupal_retrieve_form(). Here, the second element of$argsseems to be a reference&$form_state.From this, I thought that form builder function should always take the second parameter
$form_stateas a reference even if it's not used.Is my understanding right? I'm not confident and would like to get feedback. Thank you for your time.
Comment #14
fabianx commentedHah! That is quite some research.
The trick is that we _allow_ the parameter to be passed by reference, but we don't enforce it.
Since PHP 5.4 at least the called function can decide if they want to have it passed by reference or not.
In versions earlier it was always passed by reference if the caller passed a reference.
In that respect you are right:
In 5.2 $form_state is a reference, in 5.5 it is not a reference.
However:
- We already have the "wrong" behavior and don't want to change it unless absolutely needed (to keep backwards compatibility - even though a chance of conflict is < 0.000001% in this special case)
- form_state is not even used by the called function (as far as I can see), so in practice it does not matter.
IIRC we sometimes put a non-reference deliberately to show that the called code is explicitly _not_ changing the values.
Does that explanation clear things up a little?
Comment #15
hgoto commented@Fabianx, thank you so much for your kind and detailed explanation. I see. Your explanation really helps and I got clear perspective. Thank you.
I created a new patch which keeps the
$form_stateto be a value. The patch is so simple and I didn't create a interdiff.Comment #16
fabianx commentedThank you! And thanks for your effort in these Drupal 7 issues! Very much appreciated!
And this is RTBC now!
Comment #17
stefan.r commentedComment #19
stefan.r commentedCommitted and pushed to 7.x, thanks!
Comment #20
stefan.r commentedComment #21
hgoto commentedThank you!