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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 20:01:29 2024 UTC