php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46977 Extract() to work on data objects
Submitted: 2008-12-30 20:54 UTC Modified: 2014-12-30 10:41 UTC
From: michael at calwell-computing dot co dot uk Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 5.3.0alpha3 OS: All
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: michael at calwell-computing dot co dot uk
New email:
PHP Version: OS:

 

 [2008-12-30 20:54 UTC] michael at calwell-computing dot co dot uk
Description:
------------
extract() currently only extracts arrays into variables.

I think it would be good to be able to extract data objects too.


Reproduce code:
---------------
e.g.

$car1->wheels = 4;
$car1->horsepower = 40;
$car1->seats = 2;

extract($car1, EXTR_PREFIX_ALL, 'car1');

/*
$car1_wheels = 4
$car1_horsepower = 40
...
*/




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-25 02:20 UTC] james dot cohen at gmail dot com
You could get the behaviour that you want with:

extract(get_object_vars($carl), EXTR_PREFIX_ALL, 'carl');

if that helps
 [2014-04-16 22:57 UTC] levim@php.net
-Status: Open +Status: Feedback -Package: Feature/Change Request +Package: *General Issues
 [2014-04-16 22:57 UTC] levim@php.net
Given the simple work-around is this something you are interested in pursuing farther?
 [2014-12-30 10:41 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 16:01:29 2024 UTC