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
 [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: Sat Apr 20 01:01:28 2024 UTC