Brackets and assignment inside of php's IF -
question:
code 1 , code 2 has got 1 difference - brackets.
i not why 1st causes error 2nd not.
code 1:
if ( $response = $myobject->response($request) && $response2 = $myobject->response($response) // php notice: undefined variable: response )
code 2:
if ( ($response = $myobject->response($request)) && $response2 = $myobject->response($response) // ok )
&&
operator has higher precedence =
operator.
the brackets change order of evaluation desire, expressions in brackets evaluated first(as in math).
Comments
Post a Comment