php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45760 Notice: Undefined index "?:" operator
Submitted: 2008-08-08 09:45 UTC Modified: 2008-08-08 18:16 UTC
From: s dot masugata at digicom dot dnp dot co dot jp Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3CVS-2008-08-08 (snap) OS: Linux Debian(etch)
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: s dot masugata at digicom dot dnp dot co dot jp
New email:
PHP Version: OS:

 

 [2008-08-08 09:45 UTC] s dot masugata at digicom dot dnp dot co dot jp
Description:
------------
When "?:" operator is used, Notice should not be generated. 




Reproduce code:
---------------
<?php

error_reporting( E_ALL );
$user_id = $_GET['user_id'] ?: "anonymous";

echo $user_id.PHP_EOL;

?>



Expected result:
----------------
anonymous

Actual result:
--------------
Notice: Undefined index: user_id in /path/to/to/notice.php on line 4
anonymous


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-08 10:54 UTC] felipe@php.net
Hello, That behavior is expected. Coming soon it be documented.

Thanks.
 [2008-08-08 14:26 UTC] s dot masugata at digicom dot dnp dot co dot jp
Hello. :-)
Behavior expected in this case?

<?php

$_GET['user_id'] = '0';
$user_id = $_GET['user_id'] ?: "anonymous";
var_dump( $user_id );

?>

result:
string(9) "anonymous"
 [2008-08-08 18:16 UTC] felipe@php.net
Yes...

$_GET['user_id'] ?: "anonymous";
is equal to
$_GET['user_id'] ? $_GET['user_id'] : "anonymous";
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 05 04:01:35 2025 UTC