php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23441 Session variables and ternary operator
Submitted: 2003-05-01 12:15 UTC Modified: 2003-05-01 12:22 UTC
From: jeremy at wdonline dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.3.1 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jeremy at wdonline dot com
New email:
PHP Version: OS:

 

 [2003-05-01 12:15 UTC] jeremy at wdonline dot com
Through many frustrating hours, I think found a bug.  The current session documentation offers this example for setting session variables using the $_SESSION array:

if (!isset($_SESSION['count'])) {
    $_SESSION['count'] = 0;
} else {
    $_SESSION['count']++;
}


This example, of course, works.  However, it is common knowledge the the ternary operator can achieve the same results in one line:

$_SESSION['count'] = (!isset($_SESSION['count']))?0:$_SESSION['count']++;

However, this does not work.  The session variable always seems to not be set, as it always retains the value of 0 instead of being incremented.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-01 12:21 UTC] helly@php.net
the ternary operator is bork
 [2003-05-01 12:22 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

but that is not your problem!

you do a = a++;
that equals: temp = a;a = a+1;a = temp;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 01 01:01:35 2024 UTC