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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
43 + 8 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 21:01:29 2024 UTC