php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #64756 Add constructor parameter or update docs
Submitted: 2013-05-02 09:32 UTC Modified: 2021-08-03 11:34 UTC
From: luke dot brown28 at gmail dot com Assigned: cmb (profile)
Status: Wont fix Package: SPL related
PHP Version: 5.3.24 OS: Windows Server 2008
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: luke dot brown28 at gmail dot com
New email:
PHP Version: OS:

 

 [2013-05-02 09:32 UTC] luke dot brown28 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/arrayobject.construct#refsect1-
arrayobject.construct-examples
---

Currently when constructing an ArrayObject it isn't possible to specify whether 
or not you would like recursion to take place, thus traversing the array 
structure and creating ArrayObject instances in multi-dimensional arrays. 

Whilst I appreciate that this is standard behavior, being given the option when 
constructing would be very useful as you wouldn't then be required to extend the 
class for what is quite a common use-case. I appreciate it's easy to extend the 
class and code in the recursion, but I feel a param on construct would be 
equally as useful (perhaps even as part of the bitwise flags).

Failing this, the documentation should at the very least be updated to include 
an example of instantiating the class with a multi-dimensional array to show 
that any arrays within the one passed to the constructor will not be converted 
by ArrayObject. 

Test script:
---------------
$array = array('one' => 1, 'fruit' => array('lemon' => 'bitter', 'orange' => 'sweet'));

$obj = new ArrayObject($array);

$obj->fuit->orange; // null
$obj->fuit['orange'] // 'sweet'


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-03 11:34 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-08-03 11:34 UTC] cmb@php.net
> I appreciate it's easy to extend the class and code in the
> recursion, […]

There is no need to extend the class; a simple stand-alone
creation function should be sufficient.

> Failing this, the documentation should at the very least be
> updated to include an example of instantiating the class with a
> multi-dimensional array to show that any arrays within the one
> passed to the constructor will not be converted by ArrayObject.

It would rather be uncommon if the constructor behaved this way,
so I don't see a good reason to update the docs.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC