Req #75145 [Opn->Sus]: Expand support for cloning mixed content (arrays, scalars etc.).
| From: | requinix@php.net | Date: | Fri, 01 Sep 2017 12:55:34 +0000 |
| Subject: | Req #75145 [Opn->Sus]: Expand support for cloning mixed content (arrays, scalars etc.). | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210904@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75145&edit=1
ID: 75145
Updated by: requinix@php.net
Reported by: jocrutrisi at ibsats dot com
Summary: Expand support for cloning mixed content (arrays,
scalars etc.).
-Status: Open
+Status: Suspended
Type: Feature/Change Request
-Package: *General Issues
+Package: Scripting Engine problem
PHP Version: 7.2.0RC1
Block user comment: N
Private report: N
New Comment:
Thank you for your interest in PHP and for submitting a feature
request. Please be aware that due to the magnitude of change this
request requires, it would be necessary to discuss it on PHP
Internals list (internals@lists.php.net) as an RFC. Please read
the guide about creating RFCs here:
<https://wiki.php.net/rfc/howto>. If you
haven't had experience
with writing RFCs before, it is advised to seek guidance on the
Internals list (<http://php.net/mailing-lists.php>) and/or solicit
help from one of the experienced developers.
Please do not consider this comment as a negative view on the
merits of your proposal â every proposal which requires changes of
certain magnitude, even the very successful and widely supported
ones, must be done through the RFC process. This helps make the
process predictable, transparent and accessible to all developers.
Previous Comments:
------------------------------------------------------------------------
[2017-09-01 12:52:43] jocrutrisi at ibsats dot com
I just wanted to add, in case it wasn't clear, object cloning when doing "clone
$array" should be deep, i.e. arrays in arrays in arrays which contain objects should also be
cloned.
------------------------------------------------------------------------
[2017-09-01 12:48:05] jocrutrisi at ibsats dot com
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 this bug report at https://bugs.php.net/bug.php?id=75145&edit=1