Skip to content
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

Event Cart: Fix PHP 7.2 fatal error (pass by ref) #13927

Merged
merged 1 commit into from
Apr 2, 2019

Conversation

mlutfy
Copy link
Member

@mlutfy mlutfy commented Apr 1, 2019

Overview

To reproduce:

  • Use PHP 7.2
  • Enable the Event Cart
  • Create an Event, add it to the cart, then head to the cart checkout (/civicrm/event/cart_checkout).

Result: blank page / fatal error.

Technical Details

PHP Fatal error:  Only variables can be passed by reference
in [...] CRM/Event/Cart/Form/Cart.php on line 155

I'm not a fan of this function, and this seems like an incorrect usage, but I couldn't figure out how to trigger the error (for some reason, the PHP fatals, even if the code does not run on that line).

@civibot
Copy link

civibot bot commented Apr 1, 2019

(Standard links)

@civibot civibot bot added the master label Apr 1, 2019
@eileenmcnaughton
Copy link
Contributor

@mlutfy I think the better fix would be not to call that function & just call

CRM_Core_Session::singleton()->setStatus();

We seem to be calling a complex function to no benefit here

@colemanw
Copy link
Member

colemanw commented Apr 1, 2019

Yes to Eileen's suggestion, and another piece of cleanup we could do is to remove the & in displaySessionError(&$error and getMessages(&$error as it serves no purpose. Just another holdover from php4.

@mlutfy
Copy link
Member Author

mlutfy commented Apr 2, 2019

Fine by me. I was just hesitant since I don't know how to trigger/test the error.

I'd rather avoid venturing into further changes with displaySessionError, since it seems rather peculiar and hard to test. I can only say that there is now one less place in the code calling it, so that we can one day deprecate it :)

@eileenmcnaughton
Copy link
Contributor

eileenmcnaughton commented Apr 2, 2019

@mlutfy I gave it merge-on-pass but I think the last var should actually be 'error' - just from the fn signature.

   * @param string $type
   *   The type of this message (printed as a css class). Possible options:
   *     - 'alert' (default)
   *     - 'info'
   *     - 'success'
   *     - 'error' (this message type by default will remain on the screen
   *               until the user dismisses it)
   *     - 'no-popup' (will display in the document like old-school)

@mlutfy
Copy link
Member Author

mlutfy commented Apr 2, 2019

oops, indeed, thanks.

I had randomly copy-pasted, and found a few errors (grep -r setStatus . | grep fail)

./CRM/Mailing/Form/Optout.php:      CRM_Core_Session::setStatus($statusMsg, '', 'fail');
./CRM/Mailing/Form/Unsubscribe.php:      CRM_Core_Session::setStatus($statusMsg, '', 'fail');
./CRM/Mailing/Form/Unsubscribe.php:      CRM_Core_Session::setStatus($statusMsg, '', 'fail');

Fixed in #13943

@eileenmcnaughton
Copy link
Contributor

unrelated fail

@eileenmcnaughton eileenmcnaughton merged commit a875730 into civicrm:master Apr 2, 2019
@eileenmcnaughton eileenmcnaughton deleted the cart-php72 branch April 2, 2019 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants