Reply to Re: [PHP] deleting $_SESSION

Your name:

Reply:


Posted by Marek Kilimajer on 04/11/05 21:32

Jochem Maas wrote:
> AndreaD wrote:
>
>> I have a session variable called
>>
>> $_SESSION['total'] the problem is I can't delete/reset it. I have tried
>>
>> $_SESSION['total']= 0;
>>
>> $_SESSION['total']= "";
>
>
> I guess you didn't know/think of trying null:
>
> $_SESSION['total'] = null;
>
> ...which has the same effect as using:
>
> unset($_SESSION['total']); // as you have been told on at least 3 diff
> occasions ;-)
>
> this oneliner might give you a little insight:
> <?php
> $x=1;$y=2;unset($x);$y=null;var_dump($x,isset($x),empty($x),$y,isset($y),empty($y));
> ?>
>
> I encourage you to read the following pages for a better understanding
> of variables:
> http://php.net/unset http://php.net/empty http://php.net/isset,
> and this section: http://php.net/variables
>
> have fun!
> rgds,
> Jochem
>
> PS - personally I try to remember to set a var to null if the code is
> inside a loop,
> in order to minimize function call overhead. (anyone with real skill
> care to comment
> as to whether there is actually a difference between setting a var to
> null and calling unset
> on it? also speedwise?)

If you set a variable to null, it will be null. If it's unset, it no
longer exists, it's not even a null. But will evaluate to null if used
and notice will be generated.

This 7-liner will ilustrate it:

error_reporting(E_ALL);
$null = $unset = 0; // to get started
var_dump($null, $unset);
$null = null;
unset($unset);
var_dump($null, $unset); // both are nulls, but notice is generated
var_dump(array_key_exists('null', $GLOBALS), array_key_exists('unset',
$GLOBALS)); // 'unset' is no longer in $GLOBALS

Speed? I don't think there is much difference. But I would use unset()
to get rid of unused variables as they are pesistent.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация