Reply to Re: [PHP] PHP 5 Strings are References?!

Your name:

Reply:


Posted by Chris on 03/30/05 10:13

Richard Lynch wrote:

>
>
>On Tue, March 29, 2005 7:58 pm, Chris said:
>
>
>>Richard Lynch wrote:
>>
>>
>>
>>>Aha!
>>>
>>>Okay, here's the previous session question boiled down to its simplest:
>>>
>>><?php
>>> session_start();
>>> if (!isset($_SESSION['name'])){
>>> $_SESSION['name'] = 'Richard Lynch';
>>> }
>>> else{
>>> $name = $_SESSION['name'];
>>> }
>>> /* Assume a ton of code goes here */
>>> $name = 'Fooey';
>>> echo "Session name is: ", $_SESSION['name'], "<br />\n";
>>>?>
>>>
>>>Now, hit this page, re-load it, and what do *YOU* expect
>>>$_SESSION['name']
>>>to output?
>>>
>>>A) 'Richard Lynch', because you never re-assigned $_SESSION['name']
>>>B) 'Fooey' because $name is a reference, and you changed it, so that
>>>changed your session data.
>>>
>>>*I* expected A)
>>>Alas, the reality is B)
>>>
>>>Grrrrrrrr. I do *NOT* want all my strings to suddenly turn into
>>>pointers.
>>>If I wanted that kind of headache, I'd be coding in C! :-)
>>>
>>>I should have known this from the get-go, when I saw & in my session data
>>>with var_dump($_SESSION); *WHY* are strings suddenly turning into
>>>references? They're *NOT* objects!
>>>
>>>I'm about to go re-read the PHP 5 sections of the manual with a
>>>fine-tooth
>>>comb to see if I just missed this as an upgrade issue.
>>>
>>>It's pretty much going to break a hell of a lot of scripts, that's for
>>>sure.
>>>
>>>Somebody please tell me this is a Bug, not a "Feature"
>>>
>>>PHP 5.0.3
>>>FreeBSD 5.3-RELEASE
>>>
>>>
>>>
>>>
>>>
>>Are you sure you don't have register_globals enabled?
>>
>>
>
>Actually, they *ARE* enabled by my webhost.
>
>I don't really think that's relevant, however, as PHP is storing $name
>back *IN* to my $_SESSION data, just because I did:
>$name = $_SESSION['name'];
>$name = "Fooey";
>
>$name is a STRING.
>
>It's not an object.
>
>It should *NOT* be a Reference!
>
>But it is a Reference, so changing $name alters $_SESSION['name']
>
>
>
Sorry, meant to reply to list, not just you.

All I'm saying is that Sessions act extremely oddly with
register_globals enabled.

With register_globals on I believe the global variable, acts as a
reference. It's not because it's a string, it's because it's a session
variable, and it needs to keep track of changes to the variable.

[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

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