Korgan schreef:
Korgan napsal(a):
Jim Lucas napsal(a):
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.
Sorry i didnt see it :). In the script is $count = (int)$count;
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@xxxxxxxxxxxxx
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.
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'];
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