Req #74505 [Opn->Fbk]: extend get_object_vars() with 2nd parameter to avoid memory problems
| From: | requinix@php.net | Date: | Thu, 27 Apr 2017 07:27:31 +0000 |
| Subject: | Req #74505 [Opn->Fbk]: extend get_object_vars() with 2nd parameter to avoid memory problems | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-208817@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74505&edit=1
ID: 74505
Updated by: requinix@php.net
Reported by: victor at cmp dot es
Summary: extend get_object_vars() with 2nd parameter to avoid
memory problems
-Status: Open
+Status: Feedback
Type: Feature/Change Request
Package: Class/Object related
Operating System: Any
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Due to how PHP manages variables and memory, get_object_vars() won't actually result in more
memory being used for the values - just a bit for the array itself.
https://3v4l.org/aofDq
The concept is called copy-on-write: use the same actual value and only make a copy when code tries
to write or modify it.
http://www.phpinternalsbook.com/zvals/memory_management.html
Previous Comments:
------------------------------------------------------------------------
[2017-04-27 06:06:02] victor at cmp dot es
Description:
------------
When you call get_object_vars(), an array is returned, where the keys of the array are the object
properties and the values are the values of that properties.
When you need only the name of the properties (i.e. in the __sleep event for you to decide which
object vars to want to save or not in session), getting the values of laaaaaarge objects could be a
memory problem.
Adding a boolean second parameter to only return the names of the properties would avoid this
problem.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74505&edit=1