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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bart at mediawave dot nl
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Fri Oct 04 17:01:27 2024 UTC