note 59251 rejected from function.session-start by betz

From: Date: Thu, 01 Dec 2005 07:15:00 +0000
Subject: note 59251 rejected from function.session-start by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-99401@lists.php.net to get a copy of this message
Note Submitter: RamonS ---- After banging my head around for hours with PHP 5.0.2, 5.0.4 and 5.0.5 I found that on 5.0.2 this works: <?php session_start(); $text = ""; $text = $_SESSION['text']; print("$text"); ?> ..but it fails on 5.0.4 and 5.0.5. The settings for session support are identical on each PHP installation. The array $_SESSION has no elements, thus $text is empty. It magically works everywhere with all versions if I change the script to this: <?php $text = ""; session_start(); $text = $_SESSION['text']; print("$text"); ?> This time $text is exactly what was stored in the session array and the session array has all elements that were previously added to it. Anyone has an idea why this behaves this oddly from version to version ? It seems that the directive "first session, then output" needs to be more explicit: "first variable initialization, then session, then output". Generally, one can go without variable initialization, but I prefer to do this especially when getting data for inserting or modifying database records as I can set the variable values to something that will either fail or just be obvious enough to point out that some input is not there.

« previous php.notes (#99401) next »