Following on from (¯`·..Yttrium ...·´¯)'s message. . .[color=blue]
>"Joe" <sniff@email.arizona.edu> a écrit dans le message de news:
>1114648910.097437.250930@o13g2000cwo.googlegroups .com...[color=green]
>> Hi all,
>>
>> I'm a java programmer learning PHP. I was wondering how to save a
>> class over a session. As a simple example, if I wanted to have a
>> Class called Sum, which had the methods addToSum($a), and printSum().
>> Could I save that object into a session, so that I could use it later
>> as the user navigates my webpage?
>>
>> Is a session the best way to store data as a user goes between
>> webpages?
>>
>> thanks,[/color]
>
>
>Hi,
>No problem, you can do that easily.
>Sessions are made for this .. :-)
>
>[/color]
But watch out for the way PHP copies/assigns variables.
This works fine
$adder = new myAdder(0);
$adder->plus(5);
$adder->plus(7);
print($adder->total()); // 12
But this doesn't (may not)
$adder = new myAdder(0);
$adder->plus(5);
$_SESSION['ADDER']=$adder;
$adder->plus(7);
print($adder->total()); // 12
print($_SESSION['ADDER']->total()); // 5 Is this what you wanted?
But this is the way to do it
$_SESSION['ADDER']= & $adder; //<<<<<<< &
--
PETER FOX Not the same since the submarine business went under
peterfox@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>