Skip to content

Instantly share code, notes, and snippets.

@scannell
Created September 24, 2013 02:43
Show Gist options
  • Select an option

  • Save scannell/28a6319416738068fdcd to your computer and use it in GitHub Desktop.

Select an option

Save scannell/28a6319416738068fdcd to your computer and use it in GitHub Desktop.
simplexml issue
<?php
// Copyright 2004-present Facebook. All Rights Reserved.
$p = new SimpleXMLElement('<parent/>');
$c = $p->addChild('child', '123');
$c->addAttribute('attr', 'hi');
$cattrs = array();
foreach ($c->attributes() as $k => $v) {
$cattrs[$k] = $v;
}
// $p->children()[0] should be the same node as $c
$pcattrs = array();
foreach ($p->children()[0]->attributes() as $k => $v) {
$pcattrs[$k] = $v;
}
// the attribute counts should be equal!
echo count($cattrs)."\n";
echo count($pcattrs)."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment