Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #8804
| Message-ID | <50526567.RGmRr8SH6j@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2013-03-22 15:41 +0100 |
| Subject | Re: Will this set or get a SESSION variable? |
| Newsgroups | comp.lang.php |
| References | <8dd22b72-62c3-4b3c-b3ec-10ff4d682614@e16g2000yqj.googlegroups.com> <kidekm$eiu$1@speranza.aioe.org> <876cb42b-6731-44db-a25b-9ce81b49d071@y4g2000yqa.googlegroups.com> |
David Heller wrote:
> On Mar 20, 6:53 pm, Christoph Becker <cmbecke...@gmx.de> wrote:
>> David Heller wrote:
>> > I have the following code snippet:
>>
>> > if(in_array($name, $this->m_names))
>> > {
>> > $this->m_rules[$name][] = $rule;
>> > return $_SESSION[$name];
>>
>> > }
>> > In the entire script there does not appear to be any assignment to the
>> > $_SESSION super global
But most certainly in at least one other PHP script on the website.
>> > so would it be fair to say that "return $_SESSION[$name];" not only
>> > creates a session variable but returns it also?
No, it would be utter nonsense to say that.
>> > And what is it set to??
That depends on what has been stored in it previously.
>> > 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.
>> You'll find comprehensive information about PHP sessions on
>> <http://www.php.net/manual/en/book.session.php>.
>
> I'm starting to think that it does not matter if its set to anything
> because I think what the author is trying to do is just get what
> $name contains for instance if the $name is equal to Robert and he has
> something like "$anothername = Robert" and then does this:
> $_SESSION[$anothername]
> then the contents would be equal: $_SESSION[$name] ===
> $_SESSION[$anothername]
That is trivially true and does not appear to be relevant here.
> So what he is really doing is returning the
> "key" to an associative array
Most certainly not.
> since $name is a member of $m_names
Arrays do not have members, they have elements with a key and a
corresponding value. Classes, maybe even object, have members. Arrays are
not classes or objects, in PHP.
> and its also a key for $m_rules. Very clever and interesting technique of
> passing by value.
I do not follow. What does this have to do with pass-by-value?
What this code does is:
1. Search the array $this->m_names for the element whose *value* is the
value of the variable $name. (Trivially, a name.)
2. If that value is found,
a. an element is being added to the array $this>m_rules[$name] with the
value of $rule.
b. var_dump(…); (optional)
c. The value of the element in the $_SESSION array that has the key that
is the value of $name is returned. One can assume that the $_SESSION
array at that point may contain people-specific data that has been
stored previously, and restored with start_session(). It could be an
approach at caching in a database-powered application across several
document resources. BTDT.
Thus, if the value of $name is not found in $this->m_names, none of above
will happen. Something else might happen instead in the code that follows.
Please do not quote signatures unless you explicitly refer to them.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Will this set or get a SESSION variable? David Heller <daveh@allheller.net> - 2013-03-20 15:09 -0700
Re: Will this set or get a SESSION variable? Christoph Becker <cmbecker69@gmx.de> - 2013-03-20 23:53 +0100
Re: Will this set or get a SESSION variable? David Heller <daveh@allheller.net> - 2013-03-20 17:14 -0700
Re: Will this set or get a SESSION variable? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-22 15:41 +0100
Re: Will this set or get a SESSION variable? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-03-22 17:34 +0100
Re: Will this set or get a SESSION variable? Robert Heller <heller@deepsoft.com> - 2013-03-20 18:39 -0500
Re: Will this set or get a SESSION variable? Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-20 23:35 -0400
Re: Will this set or get a SESSION variable? Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-20 23:32 -0400
csiph-web