FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Will this set or get a SESSION variable?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Will this set or get a SESSION variable? [message #180869 is a reply to message #180868] Fri, 22 March 2013 16:34 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
Thomas 'PointedEars' Lahn wrote:

> David Heller wrote:
>>>> It appears to me that $_SESSION[$name] = " " or
>>>> possibly something else.
>>>
>>> You may check it out for yourself:
>>>
>>> if(in_array($name, $this->m_names))
>>> {
>>> $this->m_rules[$name][] = $rule;
>>> var_dump($_SESSION[$name]);
>>> return $_SESSION[$name];
>>>
>>> }
>>>
>>> If the session is not initialized or the session variable has not been
>>> set before, it will print NULL.
>
> As with any other PHP array when you use a non-existing key. There is
> nothing special about $_SESSION here, other than it could have been
> initialized, and the key-value pair could have been added, from session
> data set previously, elsewhere.

Another difference is that apparently the $_SESSION superglobal is *created*
by session_start():

$ php -r 'var_dump($_SESSION["foo"]);'
PHP Notice: Undefined variable: _SESSION in Command line code on line 1
PHP Stack trace:
PHP 1. {main}() Command line code:0
NULL

$ php -r 'session_start(); var_dump($_SESSION["foo"]);'
PHP Notice: Undefined index: foo in Command line code on line 1
PHP Stack trace:
PHP 1. {main}() Command line code:0
NULL

$ php -r 'var_dump($a["foo"]);'
PHP Notice: Undefined variable: a in Command line code on line 1
PHP Stack trace:
PHP 1. {main}() Command line code:0
NULL

$ php -r '$a = array(); var_dump($a["foo"]);'
PHP Notice: Undefined index: foo in Command line code on line 1
PHP Stack trace:
PHP 1. {main}() Command line code:0
NULL

$ php -r '$a = array("foo" => "bar"); var_dump($a["foo"]);'
string(3) "bar"

$ php -v
PHP 5.3.3-7+squeeze15 with Suhosin-Patch (cli) (built: Mar 4 2013 14:05:25)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with XCache v1.3.0, Copyright (c) 2005-2009, by mOo
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(at)news(dot)demon(dot)co(dot)uk> (2004)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: APC issues: locking up all processes and lack of PHP 5.4 support
Next Topic: question about class getters
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 07:50:04 GMT 2024

Total time taken to generate the page: 0.03952 seconds