php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #73057 Casting a SimpleXMLElement to an array does NOT exhibit differing behavior
Submitted: 2016-09-09 12:38 UTC Modified: 2016-09-09 15:54 UTC
From: brian dot mcclure at adition dot com Assigned: cmb (profile)
Status: Closed Package: SimpleXML related
PHP Version: Irrelevant OS: Ubuntu 16.04
Private report: No CVE-ID: None
 [2016-09-09 12:38 UTC] brian dot mcclure at adition dot com
Description:
------------
According to 5.4 changenotes, http://php.net/manual/en/migration54.other.php

there is some sort of behavior change to be expected when casting a SimnpleXMLElement to an array. But unless I'm misunderstanding what the docs mean, the bahavior is consistent all the way from 5.1 to 7.1

https://3v4l.org/F4DfI

If this is not a bug, would someone mind providing an example of the before and after behavior?

Test script:
---------------
<?php 
$xml = "<xml><first-node>foo</first-node><second-node><nested-node>bar</nested-node></second-node><third-node>baz</third-node></xml>";

$a = new SimpleXMLElement($xml);

var_export((array)$a);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-09 12:50 UTC] brian dot mcclure at adition dot com
-Summary: Casting a SimpleXMLElement to an array does exhibit differing behavior +Summary: Casting a SimpleXMLElement to an array does NOT exhibit differing behavior
 [2016-09-09 12:50 UTC] brian dot mcclure at adition dot com
fixed typo in summary
 [2016-09-09 13:24 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2016-09-09 13:24 UTC] cmb@php.net
The former behavior was sometimes buggy, and the respective change
was merely a bugfix. See <https://3v4l.org/5dQ0S> for a case where
the behavior was different before and after PHP 5.4.

I think the documentation should be improved to emphasize the
word "always".
 [2016-09-09 13:31 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2016-09-09 13:45 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=340007
Log: Fix #73057: Casting a SimpleXMLElement to an array does NOT exhibit differing behavior
 [2016-09-09 13:45 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2016-09-09 13:45 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2016-09-09 14:24 UTC] brian dot mcclure at adition dot com
Thanks for the quick responses.

to clarify, this only occurs when attempting to cast a child node of a SimpleXMLElement that has multiple children with the same name?

Are there any other scenarios?
 [2016-09-09 15:54 UTC] cmb@php.net
> to clarify, this only occurs when attempting to cast a child
> node of a SimpleXMLElement that has multiple children with the
> same name?

I believe that is the only difference, but I'm not really sure
about it. Anyhow, the relevant commit is
<https://github.com/php/php-src/commit/1e3b32c7>.
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=e5fcdd5264e78e3d17080eae66bbb94bdb4d66d9
Log: Fix #73057: Casting a SimpleXMLElement to an array does NOT exhibit differing behavior
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 25 20:01:29 2024 UTC