php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #55849 session_start() return value mismatch to docs
Submitted: 2011-10-04 23:12 UTC Modified: 2011-10-08 21:08 UTC
From: tklingeberg at lastflood dot net Assigned:
Status: Not a bug Package: Session related
PHP Version: 5.3.8 OS: Linux
Private report: No CVE-ID: None
 [2011-10-04 23:12 UTC] tklingeberg at lastflood dot net
Description:
------------
In http://www.php.net/manual/en/function.session-start.php it's written that the return value of the function:


Changelog

Version 	Description
5.3.0 	If a session fails to start, then FALSE is returned. Previously TRUE was returned.


This information is wrong. With PHP 5.3.8 on my Fedora box in CLI mode, the function returns true, even if called a second time. It gives a notice that it does not work, but it returns TRUE.

Related:

 * https://bugs.php.net/bug.php?id=2126

Test script:
---------------
<?php
session_start();
$r = session_start();
echo (int) $r;
?>

Expected result:
----------------
0

Actual result:
--------------
1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-05 03:05 UTC] tklingenberg at lastflood dot net
Related: https://bugs.php.net/bug.php?id=52982 (PHP 5.4 new session_status() function)
 [2011-10-08 21:08 UTC] frozenfire@php.net
I believe this is intended behaviour, and the documentation is correct. 
session_start() returns true if a session is started. It returns false if a 
session fails to start. What this means is that if a session is already started, 
then it has succeeded in ensuring that a session is started, because one already 
did.

To return false when the function is called, because a session is already 
started, would likely break code that uses session_start() instead of the 
upcoming session_status() function to check whether a session is available.

The documentation is correct in saying that it only returns false if the session 
*fails* to start, in the sense that no session will be available. I've verified 
this is the behaviour in the 5.3.8 release, through the source code.
 [2011-10-08 21:08 UTC] frozenfire@php.net
-Status: Open +Status: Bogus
 [2011-10-16 01:42 UTC] tklingenberg at lastflood dot net
Thanks for looking into this. I'm only concerned about the docs, not changing the return value of that function. Just to have precise information about the return value at hand when reading the manual.

"This function returns TRUE if a session was successfully started or already running, otherwise FALSE."

Are you okay with such a description of the return value? This would make it more visible that the function's return value is not only related to the action it was called for, but also that it returns the previous status from the global session context before the function was called in case a session was already active.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 00:01:31 2024 UTC