php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69889 Null coalesce operator doesn't work for string offsets
Submitted: 2015-06-20 12:16 UTC Modified: 2015-06-20 13:33 UTC
From: me at kelunik dot com Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: 7.0.0alpha1 OS:
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: me at kelunik dot com
New email:
PHP Version: OS:

 

 [2015-06-20 12:16 UTC] me at kelunik dot com
Description:
------------
http://3v4l.org/lsoFA

Test script:
---------------
<?php

$foo = "test";

var_dump($foo[0] ?? "default");
var_dump($foo[5] ?? "default");
var_dump(isset($foo[5]) ? $foo[5] : "default");

Expected result:
----------------
string(1) "t"
string(7) "default"
string(7) "default"

Actual result:
--------------
string(1) "t"
string(0) ""
string(7) "default"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-20 13:04 UTC] laruence@php.net
the problem is foo[5] returns a empty string, later in ZEND_COALESCE operands, it have no idea it whether it is a valid return..

instead of change uninitlized offset from empty string to IS_NULL(BC break?), we could also introduce a CG(error_empty_string) use in such case..

thanks
 [2015-06-20 13:09 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2015-06-20 13:12 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9fa70dbd29f91c9ae9360f19c63ada18268f5b17
Log: Fixed bug #69889
 [2015-06-20 13:12 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2015-06-20 13:25 UTC] laruence@php.net
great, I was thinking of make a PR (since BC break).. anyway, I agree this is the best way to deal with it..
 [2015-06-20 13:33 UTC] laruence@php.net
hmm, I was thinking return IS_NULL in all mode.. your fix has no bc break. :)
 [2015-06-23 18:04 UTC] ab@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9fa70dbd29f91c9ae9360f19c63ada18268f5b17
Log: Fixed bug #69889
 [2016-07-20 11:38 UTC] davey@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9fa70dbd29f91c9ae9360f19c63ada18268f5b17
Log: Fixed bug #69889
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC