|  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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-04-27 06:06 UTC] victor at cmp dot es
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-27 07:27 UTC]
-Status: Open +Status: Feedback
 [2017-04-27 07:27 UTC]
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.

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.
 [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]
-Status: Closed +Status: Wont fix
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Aug 04 17:23:21 2021 UTC