php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #74505 extend get_object_vars() with 2nd parameter to avoid memory problems
Submitted: 2017-04-27 06:06 UTC Modified: 2017-04-27 19:38 UTC
From: victor at cmp dot es Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: victor at cmp dot es
New email:
PHP Version: OS:

 

 [2017-04-27 06:06 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-27 07:27 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2017-04-27 07:27 UTC] 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 09:18 UTC] victor at cmp dot es
-Status: Feedback +Status: Closed
 [2017-04-27 09:18 UTC] victor at cmp dot es
Excelent. Thank you for the information.
 [2017-04-27 19:38 UTC] requinix@php.net
-Status: Closed +Status: Wont fix
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Mar 05 21:01:24 2021 UTC