PHP to XML Converter
Paste PHP classes or objects. Get clean XML back.
What this tool does
A PHP codebase that talks to a fulfilment partner through SoapClient, or exports products for a marketplace feed, eventually needs a sample of the XML its value objects should turn into. Building it with SimpleXMLElement::addChild() just to see the shape is slow. Paste the classes plus the new Order(...) call that fills them, and after Convert our backend hands you an XML document with the class name as the root element and each property, promoted or declared, as a child carrying the value you passed in.
It is not blind string-replacement. The converter reads modern PHP 8+ properly: constructor-promoted properties behave the same as declared ones, readonly fields come through as regular elements, typed properties (string, int, float, bool) preserve their types, DateTimeInterface values render as ISO-8601 strings, null becomes an empty element (not dropped), and arrays turn into container elements with one child per entry, matching what SimpleXMLElement or DOMDocument would typically produce.
Class structure and metadata are honoured. Each top-level class becomes a root element named after the class, public properties become child elements in declaration order, nested value objects expand inline, and array properties become wrapper elements. PHP attribute hints like #[XmlRoot("x")] or docblock tags like @XmlElement("x") rename elements where you specify them. Paste a Laravel Eloquent model, a Symfony Serializer DTO, or a plain value object: the XML comes out the way a hand-written SoapVar or SOAP request body would.
How to use it
Three steps. Same flow whether you paste one class or the entire src/Entity folder.
Paste your PHP (or try the sample)
Paste the file into the left editor, <?php tag and all. Constructor promotion, readonly properties, named arguments and backed enums are all fair game. Load Sample drops in an Order built with named arguments, two OrderItem lines (SKU-101 and SKU-202) and a Baker Street Address, with an @var OrderItem[] docblock on the items array.
You do not need to remove the <?php tag, strip namespaces, or delete docblocks. Keep the code as it looks in your IDE. Just paste.
Hit Convert
Hit the green Convert button. Your PHP is posted to our backend, which matches the constructor arguments to the promoted properties and returns the XML; the editors show a "Converting..." overlay in the meantime. Nothing in the code is executed, so a constructor that calls a database does not run.
Copy the XML
The right pane shows the document with two-space indentation and property names spelled the way you declared them ($orderId becomes <orderId>). Paste it into a PHPUnit fixture under tests/fixtures, compare it against what your SoapClient sends with __getLastRequest(), or drop it into the API docs.
When this actually comes in handy
Building SoapClient request fixtures
You are talking to a legacy SOAP endpoint via SoapClient and need a request body that matches a PHP class. Paste the class, take the XML, wrap it with SoapVar or feed it to __doRequest().
WordPress/Drupal XML exports
A custom post-type class or Drupal entity with 20 fields becomes a ready-to-edit WXR or XML export template, no more hand-crafting element structures to match the PHP shape.
Symfony/Laravel XML responses
Your API mostly returns JSON but one client still wants XML. Paste the DTO, get the XML envelope, drop it into a Symfony Response or Laravel ResponseFactory example and move on.
PHPUnit fixtures and snapshot tests
Turn value-object instances from your unit tests into XML fixture files for integration tests, contract tests, or mock SOAP servers, without hand-writing a matching XML template by eye.
Common questions
Does it handle constructor promotion and readonly properties?
Yes. Constructor-promoted parameters (public string $orderId inside __construct) become child elements just like declared properties. readonly is treated the same as a regular property for serialization: the XML is identical. PHP 8.2 readonly class also works.
Can I paste several classes at once?
Yes, as many as fit in 64 KB, which is the backend limit. When the paste includes an instance such as $order = new Order(...), that object becomes the root and the other classes appear wherever it uses them. With class definitions only and no instance, you get a skeleton filled with defaults (empty strings, 0, false), and several unrelated classes are wrapped together in one <Root> element.
How are DateTime, null, float, and bool handled?
Instances of DateTimeInterface (DateTime, DateTimeImmutable) render as ISO-8601 strings. null becomes an empty element (<field/>) rather than being omitted, so the XML shape stays consistent. float uses plain decimal notation with no locale-specific separators, and bool serializes as true/false text: matching what SimpleXMLElement produces.
What about arrays and nested objects?
An indexed array turns into a wrapper named after the property, and every entry inside gets its own child element, so the sample's two line items come out as two sibling elements, each holding sku, qty and price. Check the child tag name if a schema dictates it; rename it in the output if needed. An associative array is different: its string keys become element names directly, with characters XML does not allow replaced. Backed enums are written as their ->value, unit enums as their name.
Is my code stored?
It leaves your browser only when you press Convert: the code goes to our backend, the converted document is part of the reply, and nothing is stored on the site. .env values pasted as literals, database passwords in a PDO DSN, or real customer emails are worth swapping for placeholders first.
What if the code uses magic methods or dynamic properties?
Dynamic properties (added at runtime via __set or stdClass casting) and magic getters (__get) cannot be inferred from static code alone. The tool reads declared properties, constructor-promoted parameters, and explicit assignments. If a field only exists through __get, declare it as a property so the converter can pick it up.
Other tools you may need
Going the other way, checking the result, or producing JSON from the same PHP class? These are the pages to open next: