Jump to content

[Solved] Php Operator &= What Does It Mean?


pberce

Recommended Posts

I am in the process of making a modification to the order process and I ran across the following line of code:

 

foreach ($products AS $product)
  $success &= $cart->updateQty($product['quantity'], (int)$product['id_product'], (int)$product['id_product_attribute'], NULL, 'up');

 

I've never see the use of &= in php and I'm having trouble finding out what it means. Does this mean assign by reference?

Link to comment
Share on other sites

Hi pberce,

 

The & sign was used for passing values as reference, but now it's deprecated. In this case, the logic might be trying to update the qty in the cart, and then assign it to $success, but still have the qty in the cart modified for future use during runtime.

 

For more information on this, I suggest you check the discussions here and here.

 

I hope this helps.

 

-Mike

Link to comment
Share on other sites

Mike,

 

Thanks for the reply and the two links. One of the links linked to yet another post that talked about this. They referred to it as shorthand for the bitwise operator:

 

$a &= $b is short for $a = $a & $b

 

Which makes sense given what was being done at that point in the code, it was trying to preserve a boolean success flag over a series of attempts. If one of the updateQty calls failed during the foreach loop then the end result would be false, very clever.

 

I was initially thinking the same thing as you, that it was some type of pass by reference, but that didn't sound right to me.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...