PHPackages                             twhiston/simplexml\_debug - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. twhiston/simplexml\_debug

ActiveLibrary

twhiston/simplexml\_debug
=========================

PHP7 OOP tools for debugging your code when working with PHP's SimpleXML functions.

0.1(9y ago)12.6k↓100%PHPPHP &gt;=7.0

Since Nov 27Pushed 9y ago1 watchersCompare

[ Source](https://github.com/twhiston/simplexml_debug)[ Packagist](https://packagist.org/packages/twhiston/simplexml_debug)[ RSS](/packages/twhiston-simplexml-debug/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (2)Used By (0)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e60a578db95a95fa04d6a1f4cd134b690d15fa0bb11fb0b418986b1fafc8fb6b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7477686973746f6e2f73696d706c65786d6c5f64656275672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/twhiston/simplexml_debug/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/b6e5b226aa89541043853b7d3d97e8bf1d3fb0255bc08550719b7c9ab59ca200/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7477686973746f6e2f73696d706c65786d6c5f64656275672f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/twhiston/simplexml_debug/?branch=master)[![Build Status](https://camo.githubusercontent.com/b0b4b0e3d98da1e31bea3d8e88a3b2d17bc050b26c5b715a249eba3185751a3b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7477686973746f6e2f73696d706c65786d6c5f64656275672f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/twhiston/simplexml_debug/build-status/master)

Why?
====

[](#why)

PHP's [SimpleXML](http://php.net/simplexml) extension is a powerfully simple way of accessing and manipulating XML documents in a "PHP-ish" way. But although using it feels like using a PHP object, there is an awful lot of magic that enables it to work that way, which is poorly documented, and poorly understood.

One of the key mistakes people make when working with SimpleXML is to reach for the familiar debug outputs: `print_r`, `var_dump`, `var_export`. But *none of these work* because **a SimpleXML object isn't a real PHP object** - it's just a wrapper around a lower-level XML parser.

**Rule number 1 of SimpleXML: You do not `print_r` SimpleXML**

So the obvious question is: What do I use instead when I want to inspect my SimpleXML objects? This project aims to be the answer to that question.

What?
=====

[](#what)

- The first piece of this project is a simple function - `simplexml_dump()` - which echoes a basic summary of any `SimpleXMLElement` object you give it.
- Early feedback from users on StackOverflow was that a fully recursive function would be useful, although this would obviously need to do something different from an XML pretty-printer. The next function is therefore `simplexml_tree()` which shows an entire XML structure in summarised tree form. The output is designed to show exactly what operators and methods are needed to access each node shown.

Features
--------

[](#features)

Read the PHPDoc, and try it out, to see exactly how it works but to give you a taste:

- Can display any of the varieties of object produced while navigating a SimpleXML structure: single elements, lists of elements, single attributes, lists of attributes.
- Displays the namespace alias and URI of the current element, and all its direct children.
- Lists the total number and name of all attributes on an element (broken down by namespace).
- Lists the total number of direct children (broken down by namespace) along with a summary of their names (e.g. the fact that there are 500 `Result` elements and 1 `Info` element).
- Shows complete string content of a node, *including CDATA*.

Changes
-------

[](#changes)

- OOP style
- Always returns the debug string, so you can print it in an appropriate way in your own program instead of a default echo

Limitations and Warnings
------------------------

[](#limitations-and-warnings)

- There is currently no way of distinguishing between *a single element* (e.g. `$sxml->Result[0]`) and a *list of elements* (e.g. `$sxml->Result` or `$sxml->children()`) which happens to include only one item. They can however behave differently - `foreach ( $sxml->Result[0] as $result )` is equivalent to `foreach ( $sxml->Result[0]->children() as $result )`.
- The [`xpath()`](http://php.net/manual/en/simplexmlelement.xpath.php) method **doesn't** return a `SimpleXMLElement`, but an actual array of objects. `simplexml_dump()` will currently return an error if you try to pass it this array.
- Namespace handling is somewhat tricky, and there may be edge-cases which are not handled correctly.

Who?
====

[](#who)

This project was originated by Rowan Collins, AKA IMSoP. My homepage is at , and you can reach me by e-mail on the obvious addresses @ that domain. Turned into an OOP style by Tom Whiston

The code here is free to use for any purpose whatsoever, but with a polite request that you treat it like Free Software, and a strong request that you don't pass it off as your own. I'm happy for you to take it away, improve it, use it for whatever you like, but I'd like you to credit me as the originator. I'd also be more than happy to hear what you do with it, and how you've improved on it.

###  Health Score

27

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 55.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3402d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ecaa55475605a7bf0530e02ae6e6b71ae82e08c5471179b3563cd2469c19ab8?d=identicon)[twhiston](/maintainers/twhiston)

---

Top Contributors

[![IMSoP](https://avatars.githubusercontent.com/u/667364?v=4)](https://github.com/IMSoP "IMSoP (15 commits)")[![twhiston](https://avatars.githubusercontent.com/u/17698613?v=4)](https://github.com/twhiston "twhiston (7 commits)")[![joshtronic](https://avatars.githubusercontent.com/u/112741?v=4)](https://github.com/joshtronic "joshtronic (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/twhiston-simplexml-debug/health.svg)

```
[![Health](https://phpackages.com/badges/twhiston-simplexml-debug/health.svg)](https://phpackages.com/packages/twhiston-simplexml-debug)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
