Bug #72813 [NEW]: Different behavior for PHP 5.6.* and PHP 7.* when values are returned by ref.
From: smilimko at gmail dot com
Operating system: Windows 10
PHP version: 7.0.9
Package: Class/Object related
Bug Type: Bug
Bug description:Different behavior for PHP 5.6.* and PHP 7.* when values are returned by ref.
Description:
------------
I use PHP 7.0.4
When I run the script represented below I get the different result for
versions 5.6.* and 7.0. If it is not a bug I would want to know what
changes were made in PHP that may cause that different behavior.
Test script:
---------------
class Test
{
private $props = ['a' => 'text', 'b' => 1];
public function &__get($prop)
{
return $this->props[$prop];
}
public function __set($prop, $value)
{
if ($prop === 'b') $value = [$value];
$this->props[$prop] = $value;
}
public function getProperties()
{
return [$this->props];
}
}
$obj = new Test;
$obj->b = $obj->b;
print_r($obj->getProperties());
Expected result:
----------------
Array
(
[0] => Array
(
[a] => text
[b] => Array
(
[0] => 1
)
)
)
Actual result:
--------------
Array
(
[0] => Array
(
[a] => text
[b] => Array
*RECURSION*
)
)
--
Edit bug report at https://bugs.php.net/bug.php?id=72813&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72813&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72813&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72813&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72813&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72813&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72813&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72813&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72813&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72813&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72813&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72813&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72813&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72813&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72813&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72813&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72813&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72813&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72813&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72813&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72813&r=mysqlcfg
Thread (3 messages)
- smilimko at gmail dot com