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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Fri Nov 01 01:01:28 2024 UTC