Req #75145 [NEW]: Expand support for cloning mixed content (arrays, scalars etc.).

From: Date: Fri, 01 Sep 2017 12:48:11 +0000
Subject: Req #75145 [NEW]: Expand support for cloning mixed content (arrays, scalars etc.).
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210902@lists.php.net to get a copy of this message
From: jocrutrisi at ibsats dot com Operating system: PHP version: 7.2.0RC1 Package: *General Issues Bug Type: Feature/Change Request Bug description:Expand support for cloning mixed content (arrays, scalars etc.). Description: ------------ Cloning is a built-in operation in PHP, with its own token and opcode. Currently it works only on objects, but there's no reason for this restriction. There are also some valid use cases for cloning non-object values, which are not currently addressed, namely obtaining a "clone" of an array which contains objects (more on the proposal below). I propose: 1. Cloning continues to work on objects as it does now (no BC breaks). 2. Cloning is a NO-OP for: null, scalars; it just returns the value passed to clone. Semantically this works as null+scalars are either immutable, or copy-on-write. 3. Cloning for resources fails as it does now, because resources are not cloneable. --- Here comes the interesting part --- 4. Cloning for arrays returns a copy of the array, *where all values that are objects have been cloned*. Currently there's no way to obtain a comprehensive "clone" of an array containing objects like this, aside from implementing a recursive function/method to scan the array and do it (slow). So I think it'll be a useful addition and make clone less prone to throwing fatal errors when it semantically doesn't have to. -- Edit bug report at https://bugs.php.net/bug.php?id=75145&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75145&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75145&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75145&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75145&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75145&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75145&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75145&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75145&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75145&r=support Expected behavior: https://bugs.php.net/fix.php?id=75145&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75145&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75145&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75145&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75145&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75145&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75145&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75145&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75145&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75145&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75145&r=mysqlcfg

« previous php.bugs (#210902) next »