Bug #75632 [NEW]: Wrong behavior of clone and references

From: Date: Tue, 05 Dec 2017 14:08:16 +0000
Subject: Bug #75632 [NEW]: Wrong behavior of clone and references
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212941@lists.php.net to get a copy of this message
From: kripper at imatronix dot com Operating system: All PHP version: 7.1.12 Package: Scripting Engine problem Bug Type: Bug Bug description:Wrong behavior of clone and references Description: ------------ Setting a unused reference to a cloned object property, prevents the object to be cloned. This makes no sense and is intuitive. Test script: --------------- $orig = new stdClass(); $orig->test = 'original'; $ptr = & $orig->test; // <--- Setting an unused reference changes the behaviour $copy = clone $orig; $copy->test = "modified"; die("Orig is: {$orig->test}"); // Gives 'modified' instead of 'original' Expected result: ---------------- $orig->test should give 'original' since we cloned the object. A cloned object should be a cloned object, no matter of unused references. Actual result: -------------- Setting a reference makes "$copy = clone $original" to behave just like "$copy = $original" (a reference). Not setting or unsetting the refernce, fixes the behavior. -- Edit bug report at https://bugs.php.net/bug.php?id=75632&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75632&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75632&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75632&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75632&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75632&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75632&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75632&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75632&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75632&r=support Expected behavior: https://bugs.php.net/fix.php?id=75632&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75632&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75632&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75632&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75632&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75632&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75632&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75632&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75632&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75632&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75632&r=mysqlcfg

« previous php.bugs (#212941) next »