PHP 5 Strings are References?!

From: Date: Wed, 30 Mar 2005 03:18:34 +0000
Subject: PHP 5 Strings are References?!
Groups: php.general 
Request: Send a blank email to php-general+get-211836@lists.php.net to get a copy of this message
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 -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#211836) next »