does checking what sessions var contain implicitly check for it's existance?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NotGiven

    does checking what sessions var contain implicitly check for it's existance?

    In other words if I want to check if $SESSION['temp'] = 'A',
    do I also NEED to check isset($_SESSION['temp']) ?

    If so, what logical IF statement works? I f have tried for an hour to come
    up with a IF statement that works:

    if ((isset($_SESSI ON['temp']))AND($_SESSION['temp'] = 'A'))
    echo "set and same";
    else
    echo "not (set & same)";

    if ((!isset($_SESS ION['temp']))OR(!$_SESSION['temp'] = 'A'))
    echo "not set or not same";
    else
    echo "set or same)";

    None seem to work

    Thanks for help.




  • Tim Van Wassenhove

    #2
    Re: does checking what sessions var contain implicitly check for it's existance?

    In article <_DQHc.27299$o6 2.12725@bignews 2.bellsouth.net >, NotGiven wrote:[color=blue]
    > In other words if I want to check if $SESSION['temp'] = 'A',[/color]

    = is for assignment. == is used for comparision.
    [color=blue]
    > if ((isset($_SESSI ON['temp']))AND($_SESSION['temp'] = 'A'))[/color]

    I don't know (read too lazy to look it up right now) if there is
    somewhere defined how multiple conditions will be evaluated (as in from
    left to right or from right to left or random).

    But untill now testing first if the variable isset, and then testing if
    it equals something has always worked.

    if (isset($foo) && $foo == 'bar')


    --
    Tim Van Wassenhove <http://home.mysth.be/~timvw>

    Comment

    • Pedro Graca

      #3
      Re: does checking what sessions var contain implicitly check for it's existance?

      NotGiven wrote:[color=blue]
      > If so, what logical IF statement works? I f have tried for an hour to come
      > up with a IF statement that works:[/color]

      You almost got it :)
      [color=blue]
      > if ((isset($_SESSI ON['temp']))AND($_SESSION['temp'] = 'A'))[/color]
      ^^^

      The "=" is the assignment operator, you need the 'test for equality'
      operator:

      if ((isset($_SESSI ON['temp'])) AND ($_SESSION['temp'] == 'A'))
      ^^^^

      --
      USENET would be a better place if everybody read: | to email me: use |
      http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
      http://www.netmeister.org/news/learn2quote2.html | header, textonly |
      http://www.expita.com/nomime.html | no attachments. |

      Comment

      • Chung Leong

        #4
        Re: does checking what sessions var contain implicitly check for it's existance?

        "NotGiven" <noname@nonegiv en.net> wrote in message
        news:_DQHc.2729 9$o62.12725@big news2.bellsouth .net...[color=blue]
        > In other words if I want to check if $SESSION['temp'] = 'A',
        > do I also NEED to check isset($_SESSION['temp']) ?[/color]

        No, you don't need to. Accessing an undefined variable yields null, which
        automatically gets converted to an empty string when you do a string
        comparison. So if($_SESSION['temp'] == 'A') would be false if
        $_SESSION['temp'] wasn't set.

        If error_reporting is set to show E_NOTICE, do this to suppress the warning:

        if(@$_SESSION['temp'] == 'A') {
        }



        Comment

        Working...