php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #16700 Code samples relating to use of sessions is broken, and other issues.
Submitted: 2002-04-19 12:39 UTC Modified: 2002-04-19 12:49 UTC
From: justin at quadmyre dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.1.2 OS: All (tested on win32 and linux)
Private report: No CVE-ID: None
 [2002-04-19 12:39 UTC] justin at quadmyre dot com
Please don't disregard this, it is not just a product of the 4.1.2 win32 $_SESSION bug.

The examples 1,2 and 3 regarding the use of $_SESSION and $HTTP_SESSION_VARS all omit to mention that you still have to call session_start() before you can use any of them. The caution regarding mixing use of these variables and the session functions compounds this.

<?php
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
    $_SESSION['count'] = 0;
} else {
    $_SESSION['count']++;
}
?>

The example simply does not work under any version of PHP, and is extremely confusing for newbies, and an intense waste of time for those of us who found out about the win32 $_SESSION bug the hard way.

They should read:

Example 1:
<?php
session_start();
if (isset($HTTP_SESSION_VARS['count'])) {
   $HTTP_SESSION_VARS['count']++;
}
else {
   $HTTP_SESSION_VARS['count'] = 0;
}
?>

Example 2:
<?php
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
session_start();
if (!isset($_SESSION['count'])) {
    $_SESSION['count'] = 0;
} else {
    $_SESSION['count']++;
}
?>

Example 3:
<?php
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
session_start();
unset($_SESSION['count']);
?>

I would also recommend adding the following notes:

Note: When using $_SESSION or $HTTP_SESSION_VARS to register / get session variables, you must call session_start() to start the session, otherwise no session information will be saved.

Note: In the **Win32 only** build of PHP 4.1.2, support for $_SESSION and $HTTP_SESSION_VARS is broken, and no data is stored in the session file. Session_register() etc still works, but since the use of register_globals / session_register() is depracated and many people have now disabled register_globals anyhow, the workaround currently is to downgrade to PHP 4.1.1 / 4.1.0, or wait for the next release version. **This bug does not affect any linux builds of PHP**.

I know that seccond note is not the sort of thing you probably want to publicise, but having read the current discussions on this bug the official line seems to be that the bug is fixed in the upcoming 4.2.0 but 4.1.2 is not going to be re-released. However, most people developing on win32 at the moment, and many people in the future are going to come up against the problem and be stumped.

There should also be a note on the download page warning people who are currently blindly being advised to upgrade to 4.1.2 that this bug is present in the win32 build, and 4.1.1 offered as an alternative on the win32 platform.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-19 12:49 UTC] sander@php.net
I've fixed the examples. 4.2.0 will be released really soon now so there's (IMHO) no need to update the docs for that.
 [2009-07-21 18:12 UTC] svn@php.net
Automatic comment from SVN on behalf of mike
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=284553
Log: fix bug #16700 - array properties of class extending HttpMessage
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 18:01:28 2024 UTC