Re: Bug in array_key_exist?
| From: | Jochem Maas | Date: | Sat, 30 Aug 2008 15:51:06 +0000 |
| Subject: | Re: Bug in array_key_exist? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-279096@lists.php.net to get a copy of this message | ||
Korgan schreef:
Korgan napsal(a):no point in anyone trying to help you then, because you don't post the code you use, you post something else instead ... this is not php-psychics@lists.php.net btw there is practically no chance of a bug being in array_key_exists() and you being the first to spot it, as a function it's used way too much to be able to fly under the bug radar. jmho.Jim Lucas napsal(a):Sorry i didnt see it :). In the script is $count = (int)$count;Korgan wrote: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;Let me point at it ^^^^Check your spelling If error_reporting was set to E_ALL AND display_errors were turned on, you would see that you are using an undefined variable in your method called $cout, casting is as an int and assigning the resulting value (which would always be zero) to $count.
After add a item value is ok look at first B vardump which is on the end of the script.No variable $count is mandatory so that is defined. But its not main idea of my question... Function add items correctly, but if go to next page, values in array change. Values are changed passing from one page to another one, why and where?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'];elsenew..... .. /** 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 : 4B: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 :)