PHPackages                             garyjones/php-type-converter - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. garyjones/php-type-converter

AbandonedArchivedLibrary[Parsing &amp; Serialization](/categories/parsing)

garyjones/php-type-converter
============================

Converts one resource to another (XML, JSON, Object, Array, Serialization). PSR-2. Supports nested resources.

524PHP

Since Jan 26Pushed 10y ago1 watchersCompare

[ Source](https://github.com/GaryJones/php-type-converter)[ Packagist](https://packagist.org/packages/garyjones/php-type-converter)[ RSS](/packages/garyjones-php-type-converter/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

PHP Type Converter
==================

[](#php-type-converter)

A class that handles the detection and conversion of certain resource formats / content types into other formats.

The current formats are supported: XML, JSON, Array, Object, Serialized

Requirements
------------

[](#requirements)

- PHP 5.3.0+
- [SimpleXML](http://php.net/manual/book.simplexml.php)

Documentation
-------------

[](#documentation)

The class is pretty straight forward. If you want to convert something to another format, use the "to" methods.

```
$object = TypeConverter::toObject($resource);
$array = TypeConverter::toArray($resource);
$json = TypeConverter::toJson($resource);
$xml = TypeConverter::toXml($resource);
$ser = TypeConverter::toSerialize($resource);
```

If you want to detect what resource type it is, use the "is" methods. If you use the "to" methods above, it does automatic "is" detection.

```
TypeConverter::isObject($resource);
TypeConverter::isArray($resource);
TypeConverter::isJson($resource);
TypeConverter::isXml($resource);
TypeConverter::isSerialized($resource);
```

If you want a string representation of what a resource is, use the default is() method.

```
$resource = array();
TypeConverter::is($resource); // array
```

You can convert an XML document into an array (must have SimpleXML).

```
$array = TypeConverter::xmlToArray($xml, TypeConverter::XML_MERGE);
```

When using xmlToArray(), you can define the format in which the node attributes and values are presented. The following constants are available.

- `XML_NONE` - Disregard XML attributes and only return the value.
- `XML_MERGE` - Merge attributes and the value into a single dimension; the values key will be "value".
- `XML_GROUP` - Group the attributes into a key of "attributes" and the value into a key of "value".
- `XML_OVERWRITE` - Attributes will only be returned.

Status
------

[](#status)

[![Build Status](https://camo.githubusercontent.com/3735c662e588cb4316a81c1c812244a9eca94347fb70e4ab6e27f9dc42980135/68747470733a2f2f7472617669732d63692e6f72672f476172794a6f6e65732f7068702d747970652d636f6e7665727465722e706e67)](https://travis-ci.org/GaryJones/php-type-converter)

Changelog
---------

[](#changelog)

Originally forked from Type Converter v2.0.0 [https://github.com/milesj/php-type\_converter](https://github.com/milesj/php-type_converter) by [Miles Johnson](https://twitter.com/gearvOsh).

This fork adds support for conversion of nested combinations of arrays / objects and some unit tests.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 56.8% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ba7751eebec0f74a4963e9a062f49e58222b97872bf193d95f0505f3df321d09?d=identicon)[GaryJones](/maintainers/GaryJones)

---

Top Contributors

[![milesj](https://avatars.githubusercontent.com/u/143744?v=4)](https://github.com/milesj "milesj (21 commits)")[![GaryJones](https://avatars.githubusercontent.com/u/88371?v=4)](https://github.com/GaryJones "GaryJones (16 commits)")

### Embed Badge

![Health badge](/badges/garyjones-php-type-converter/health.svg)

```
[![Health](https://phpackages.com/badges/garyjones-php-type-converter/health.svg)](https://phpackages.com/packages/garyjones-php-type-converter)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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