Req #74505 [Fbk->Csd]: extend get_object_vars() with 2nd parameter to avoid memory problems
| From: | victor at cmp dot es | Date: | Thu, 27 Apr 2017 09:18:13 +0000 |
| Subject: | Req #74505 [Fbk->Csd]: 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-208818@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
User updated by: victor at cmp dot es
Reported by: victor at cmp dot es
Summary: extend get_object_vars() with 2nd parameter to avoid
memory problems
-Status: Feedback
+Status: Closed
Type: Feature/Change Request
Package: Class/Object related
Operating System: Any
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Excelent. Thank you for the information.
Previous Comments:
------------------------------------------------------------------------
[2017-04-27 07:27:28] requinix@php.net
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
------------------------------------------------------------------------
[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