Bug #65903 [NEW]: Reference type property unexpectedly converted to value type property
| From: | veg at tut dot by | Date: | Tue, 15 Oct 2013 19:09:24 +0000 |
| Subject: | Bug #65903 [NEW]: Reference type property unexpectedly converted to value type property | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-182298@lists.php.net to get a copy of this message | ||
From: veg at tut dot by
Operating system: Windows 7 Pro SP1 x86
PHP version: 5.5.4
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Reference type property unexpectedly converted to value type property
Description:
------------
I've used a little code snippet to convert property from value type to
reference type. It's described here:
http://www.php.net/manual/en/language.oop5.cloning.php
It's very useful practice when you want to share some properties between
all clones. But it works with some bugs. When you try to read a
reference type property of object without clones, this property
unexpectedly converted to value type property.
Test script:
---------------
<?php
header('content-type: text/plain; charset=utf-8');
class demo
{
public $n = 0;
function __construct() { $this->n =& $this->n; }
function magic() { if ($this->n) return; }
function set($n) { $this->n = $n; }
}
// Outputs 1 = 1 as expected
$a1 = new demo();
$b1 = clone $a1;
$a1->magic();
$b1->set(1);
echo "{$a1->n} = {$b1->n}\n";
// Outputs 0 = 1 (magic() method is called a little earlier)
$a2 = new demo();
$a2->magic();
$b2 = clone $a2;
$b2->set(1);
echo "{$a2->n} = {$b2->n}\n";
Expected result:
----------------
1 = 1
1 = 1
Actual result:
--------------
1 = 1
0 = 1
--
Edit bug report at https://bugs.php.net/bug.php?id=65903&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65903&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=65903&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65903&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65903&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65903&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65903&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65903&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65903&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65903&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65903&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65903&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65903&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65903&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65903&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65903&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65903&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65903&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65903&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65903&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65903&r=mysqlcfg