From 7c746c44853122a927a3a72a3fb27479bcf4a287 Mon Sep 17 00:00:00 2001 From: Rowan Collins Date: Sat, 13 Oct 2012 23:56:26 +0100 Subject: [PATCH] Fix child name hash not to give "undefined array key" Notices --- simplexml_dump.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/simplexml_dump.php b/simplexml_dump.php index c3510f0..b7134e9 100644 --- a/simplexml_dump.php +++ b/simplexml_dump.php @@ -137,7 +137,17 @@ function simplexml_dump(SimpleXMLElement $sxml, $return=false) $child_names = array(); foreach ( $children as $sx_child ) { - $child_names[ $sx_child->getName() ]++; + // Below is a rather clunky way of saying $child_names[ $sx_child->getName() ]++; + // which avoids Notices about unset array keys + $child_node_name = $sx_child->getName(); + if ( array_key_exists($child_node_name, $child_names) ) + { + $child_names[$child_node_name]++; + } + else + { + $child_names[$child_node_name] = 1; + } } ksort($child_names); $child_name_output = array();