RE: Re[2]: [PHP] beginner in PHP
| From: | Ford, Mike [LSS] | Date: | Mon, 17 Jun 2002 17:22:08 +0000 |
| Subject: | RE: Re[2]: [PHP] beginner in PHP | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-102800@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Stuart Dallas [mailto:stuart@sharedserver.net]
> Sent: Thursday, June 13, 2002 2:53 PM
> To: Phillip Perry
> Cc: Tim Ward; Martin Towell; Tom Rogers; Php
> Subject: Re[2]: [PHP] beginner in PHP
>
>
> On Thursday, June 13, 2002 at 7:44:39 PM, you wrote:
>
> > Yes, here is the checkout code I used...
>
> > function chout(){
> > session_destroy();
> > unset ($mycart);
> > unset ($cart_items);
> > echo "<p>Thank you for shopping!</p>";
> > }
>
> > Any suggestions?
>
> Try this...
>
> function chout(){
> global $mycart, $cart_items;
> session_destroy();
> unset ($mycart);
> unset ($cart_items);
> echo "<p>Thank you for shopping!</p>";
> }
Still won't work. All that the "global" statement does is make the copy of the
variable inside the function be a *reference* to the global copy -- it's basically equivalent
to
$mycart = & $GLOBALS['mycart'];
So, when you unset($mycart) within the function, all you're unsetting is the reference -- the
actual global variable is completely unaffected. Thus, the only way to unset a global variable is
to reference it in the global context. One way to do this might be:
function chout(){
session_destroy();
unset ($GLOBALS['mycart']);
unset ($GLOBALS['cart_items']);
}
Alternatively, just do it in the global context, outside any function.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211