Bug in array_key_exist?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
I have a problem with array_key_exists in if statement.

I have a class with this function

class XXX {
	private items = array();
...
...
...

public function addXXX($id, $count)
    {
       $count = (int)$cout;
        if (!array_key_exists($id, $this->items))
           $this->items[$id] = $count;
        else
           $this->items[$id] += $count;
    }

...
...

}

And I want to send instance of this class with SESSION.
If I add a item to the array, count is ok, but if i go to the next page count will change.


There is the code of index.php

 /** its loading classes ***/
 spl_autoload_register('loadClass');

 session_start();
 var_dump($_SESSION['XX']); /** A **/

 ....
 ...
 ...
 ...
 if ($_SESSION['XX'] instanceof XXX)
	$x = $_SESSION['XX'];
  else
	new...
  ..
  ..
  /** Do onzl this **/
  if ....
	$x->addXXX($id, $cnt);


  ....
  ...
  ...
  $_SESSION['XX'] = X;
  var_dump($_SESSION['XX']); /** B **/


There is a vardump if action addXXX exec:
   A:
	object(Kosik)#1 (1) { ["zbozi:private"]=>  array(0) { } }

   B:
	object(Kosik)#1 (1) { ["zbozi:private"]=>  array(1) { [1]=>  int(1) } }

And than i will go to some page and vardums are:
   A:
object(Kosik)#1 (1) { ["zbozi:private"]=> array(1) { [1]=> int(4) } } 1 : 4

   B:
	 object(Kosik)#1 (1) { ["zbozi:private"]=>  array(1) { [1]=>  int(4) } }

I am thinking that do both codes in if statement,
but $this->items[$id] += $count; exec after send page.



I am using PHP Version 5.2.6 and Smarty v.2.6.19

Thanks for help :)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux