php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53989 Notice: Undefined variable/index with xor, but not with or
Submitted: 2011-02-11 03:18 UTC Modified: 2011-02-11 22:21 UTC
From: martin at feredoras dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.5 OS: Tested only with Windows
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: martin at feredoras dot de
New email:
PHP Version: OS:

 

 [2011-02-11 03:18 UTC] martin at feredoras dot de
Description:
------------
I want to check, if a variable is not set. If the variable is not set, i want to 
check, if this variable has a special value. There is no problem with "or", but 
with "xor" outputs a notice.

Test script:
---------------
<?
session_start();

if(!isset($_SESSION['foo']) xor $_SESSION['foo'] == 1) echo "foo";
if(!isset($bar) xor $bar== 1) echo "bar";

if(!isset($_SESSION['foo']) or $_SESSION['foo'] == 1) echo "foo";
if(!isset($bar) or $bar== 1) echo "bar";

?>

Expected result:
----------------
foobarfoobar

Actual result:
--------------
Notice: Undefined index: foo in C:\xampp\htdocs\feredoras\testing.php on line 4
foo
Notice: Undefined variable: bar in C:\xampp\htdocs\feredoras\testing.php on line 5
barfoobar

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-11 22:21 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2011-02-11 22:21 UTC] felipe@php.net
This is because the OR logical expression doesn't requires the right expression to be executed when the first expression is evaluated to true. But XOR requires.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Dec 06 10:00:01 2025 UTC