[thelist] [PHP] PHP5 and the use of += ?

Lawrence Oluyede l.oluyede at gmail.com
Tue Aug 19 04:51:49 CDT 2008

On Tue, Aug 19, 2008 at 11:40 AM, Tris <beertastic at gmail.com> wrote:
> Hi all...
> I'm currently moving a shopping basket from a PHP 4 server to a PHP 5
> serrver and it's 90% ok.
> However,
> The shopping basket system, currently loops through the items in the
> users basket and keeps a tally of the total cost using this:
> $finalPrice += $itemPrice;
> In each loop of the basket checker..
> However, in the new server, it seems to be adding up more than it needs to.
> As if it's doing for each loop:
> $finalPrice = $finalPrice + $finalPrice + $itemPrice;
> So the more goes into the basket, the more out ther final price is..

This sounds wrong to me. The first is like:

a = a + b

The second is like

a = (2 * a) + b

So definitely is overcharging :)

Lawrence, stacktrace.it - oluyede.org - neropercaso.it
"It is difficult to get a man to understand
something when his salary depends on not
understanding it" - Upton Sinclair

More information about the thelist mailing list