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
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: 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

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-2022 The PHP Group
All rights reserved.
Last updated: Mon May 23 08:05:45 2022 UTC