You are here: Re: [PHP] deleting $_SESSION « PHP « IT news, forums, messages
Re: [PHP] deleting $_SESSION

Posted by Marek Kilimajer on 04/12/05 00:52

Jochem Maas wrote:
> Marek Kilimajer wrote:
>
>> Jochem Maas wrote:
>>
>>> John Nichel wrote:
>>>
>>>> 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 ;-)
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Not true. If you set it to null, it still exists...it's just null.
>>>> If you unset it, the variable no longer exists.
>>>
>>>
>>>
>>>
>>> fair enough, but then how do you differentiate between a var that
>>> exists and is null
>>> and a non-existant var?
>>>
>>> Marek pointed out that setting error reporting to E_ALL, shows a notice
>>> when you var_dump() the unset() var and not the null var, but other
>>> than that
>>> the unset() var and the null var give the same result from isset()
>>> and empty()
>>> e.g:
>>>
>>> error_reporting(E_ALL);
>>> $X = array("total" => 1);
>>> $X["total"] = null;
>>> if ( isset ( $X["total"] ) ) {
>>> echo ( "Yes" );
>>> } else {
>>> echo ( "No" );
>>> }
>>> var_dump( $X["total"] );
>>> unset ( $X["total"] );
>>> if ( isset ( $X["total"] ) ) {
>>> echo ( "Yes" );
>>> } else {
>>> echo ( "No" );
>>> }
>>> var_dump( $X["total"] );
>>>
>>> which produces the following for me:
>>>
>>> NoNULL
>>> NoPHP Notice: Undefined index: total in Command line code on line 23
>>> NULL
>>>
>>> so that means you would have to set a suitable error handler for
>>> E_NOTICE just before
>>> the place you want to check if the var exists and unset it
>>> immediately afterwards??
>>
>>
>>
>> No, use isset() or empty() to check if the variable exists and you
>> won't get notices
>>
>
> right, I'm thinking about it too much - getting confused for no reason :-).
> but that still leaves the point that you can't tell the difference
> between a
> null var and one that is not set at all - this seems odd if there is
> actually
> a difference (okay so you can tell the difference but it seems to
> require that
> you generate an E_NOTICE which is not the idea really is it).

You can use get_defined_vars() and array_key_exists() if you really need to.

 

Navigation:

[Reply to this 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

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