php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #28462 Cast array to properties of custom objects
Submitted: 2004-05-20 22:51 UTC Modified: 2004-05-21 12:03 UTC
From: bart at mediawave dot nl Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.0.0RC2 OS: Irrelevant
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 !
Your email address:
MUST BE VALID
Solve the problem:
21 + 1 = ?
Subscribe to this entry?

 
 [2004-05-20 22:51 UTC] bart at mediawave dot nl
Description:
------------
A lot of functions in PHP return arrays in stead of objects. Of course it's possible to simply cast the return value to an object like:

$urlObject = (object) parse_url($url);

But then I would get an instance of the stdClass. I can imagine situations where people would like to cast arrays into properties of their own custom objects. Maybe something like:

cast_array2object($array, $someCustomObject);

or something like:

$this .= (object) parse_url($url);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-21 11:59 UTC] bart at mediawave dot nl
Another option is to simply add the array as a property to the custom object. Then use __get() and __set() to simulate object properties with the array.
 [2004-05-21 12:03 UTC] bart at mediawave dot nl
Changing this to bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC