Bug #71870 [NEW]: [][index] syntax emits a "Undefined variable: offset" notice
From: nish dot aravamudan at canonical dot com
Operating system: Ubuntu 16.04
PHP version: 7.0.4
Package: Arrays related
Bug Type: Bug
Bug description:[][index] syntax emits a "Undefined variable: offset" notice
Description:
------------
https://3v4l.org/T9HLm
Note that with PHP5, no "undefined variable offset" is emitted. I
believe this is a BC break in PHP7.0. Also, I found this page:
https://wiki.php.net/rfc/uniform_variable_syntax,
which explicitly
mentions: "E.g. empty([]['a']) will no longer throw an undefined offset
notice."
This is seen with php-zeta-console-tools tests, and leads to a test
failure.
Test script:
---------------
<?php
error_reporting(-1);
class obj implements ArrayAccess {
private $container = array();
public function __construct() {
$this->container = array(
"one" => 1,
"two" => 2,
"three" => 3,
);
}
public function offsetSet($offset, $value) {
if (is_null($offset)) {
$this->container[] = $value;
} else {
$this->container[$offset] = $value;
}
}
public function offsetExists($offset) {
return isset($this->container[$offset]);
}
public function offsetUnset($offset) {
unset($this->container[$offset]);
}
public function offsetGet($offset) {
return isset($this->container[$offset]) ?
$this->container[$offset] : null;
}
}
$obj = new obj;
$obj[][0] = 'Append';
Expected result:
----------------
No notice to be emitted.
Actual result:
--------------
Notice: Undefined variable: offset in /in/T9HLm on line 32
--
Edit bug report at https://bugs.php.net/bug.php?id=71870&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71870&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71870&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71870&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71870&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71870&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71870&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71870&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71870&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71870&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71870&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71870&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71870&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71870&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71870&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71870&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71870&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71870&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71870&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71870&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71870&r=mysqlcfg
Thread (3 messages)
- nish dot aravamudan at canonical dot com