php-src/Zend/tests/bug69889.phpt
Nikita Popov 9fa70dbd29 Fixed bug #69889
There is one case that requires further discussion:

$foo = "test";
var_dump($foo[0.0] ?? "default");
var_dump(isset($foo[0.0]) ? $foo[0.0] : "default");

Here the former will currently return "t", while the latter also
returns "t" and additionally throws a notice.

I think we need to revisit the behavior of invalid types for string
offset access in PHP 7, as currently there is some mismatch between
what isset() does and what the access itself supports.
2015-06-20 15:09:58 +02:00

23 lines
423 B
PHP

--TEST--
Bug #69889: Null coalesce operator doesn't work for string offsets
--FILE--
<?php
$foo = "test";
var_dump($foo[0] ?? "default");
var_dump($foo[5] ?? "default");
var_dump(isset($foo[5]) ? $foo[5] : "default");
var_dump($foo["str"] ?? "default");
var_dump(isset($foo["str"]) ? $foo["str"] : "default");
?>
--EXPECT--
string(1) "t"
string(7) "default"
string(7) "default"
string(7) "default"
string(7) "default"