PHPackages                             drbonzo/metassione - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. drbonzo/metassione

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

drbonzo/metassione
==================

POPO to stdClass and POPO filler

0.7.0(9y ago)6100↑2900%3MITPHP

Since Jun 4Pushed 9y ago2 watchersCompare

[ Source](https://github.com/drbonzo/metassione)[ Packagist](https://packagist.org/packages/drbonzo/metassione)[ RSS](/packages/drbonzo-metassione/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (17)Used By (0)

metassione
==========

[](#metassione)

- Allows to convert POPO (**POPO** = Plain Old PHP Object) to stdClass
    - Why? json\_encode() does not handle private properties.
    - So you need to have all properties public or use `metassione`.
- and stdClass to POPO
    - convert your JSON to PHP objects with type checking and casting, etc

POPO to stdClass
================

[](#popo-to-stdclass)

This allows to convert complex object to stdClass, and later JSON (with `json_encode()`).

Example
-------

[](#example)

Build object hierarchy

```
$post = new \Blog\Post();
$post->setTitle('il titolo');
$post->setContents('Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Ut posuere risus eu commodo fermentum. Nullam nec dignissim est.
Curabitur adipiscing massa sit amet velit vehicula aliquam.');

{
	$comment_1 = new \Blog\Comment();
	$comment_1->setAuthorName("l'autore 1");
	$comment_1->setContents("Lorem ipsum");

	$comment_2 = new \Blog\Comment();
	$comment_2->setAuthorName("l'autore 2");
	$comment_2->setContents("dolor sit amet");

	$comments = [$comment_1, $comment_2];
	$post->setComments($comments);
}

```

Converting to stdClass:

```
$metassione = new \NorthslopePL\Metassione\Metassione();
$rawData = $metassione->convertToStdClass($post);
print_r($rawData);

```

gives:

```
stdClass Object
(
    [title] => il titolo
    [contents] => Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Ut posuere risus eu commodo fermentum. Nullam nec dignissim est.
Curabitur adipiscing massa sit amet velit vehicula aliquam.
    [comments] => Array
        (
            [0] => stdClass Object
                (
                    [authorName] => l'autore 1
                    [contents] => Lorem ipsum
                )

            [1] => stdClass Object
                (
                    [authorName] => l'autore 2
                    [contents] => dolor sit amet
                )

        )

)

```

Then we can convert that to JSON (`JSON_PRETTY_PRINT` = php 5.4+): ​ $json = json\_encode($rawData, JSON\_PRETTY\_PRINT); print($json);

which gives:

```
{
    "title": "il titolo",
    "contents": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nUt posuere risus eu commodo fermentum. Nullam nec dignissim est.\nCurabitur adipiscing massa sit amet velit vehicula aliquam.",
    "comments": [
        {
            "authorName": "l'autore 1",
            "contents": "Lorem ipsum"
        },
        {
            "authorName": "l'autore 2",
            "contents": "dolor sit amet"
        }
    ]
}

```

stdClass to POPO
================

[](#stdclass-to-popo)

This allows to convert data from JSON into POPO. Instead of reading data from unspecified objects and arrays - you can use your own classes, type hinting, etc.

With your POPOs:

```
$comments = $post->getComments();
echo $comments[0]->getAuthor();
echo $comments[0]->getContents();

```

Compare this to arrays and stdClasses (no type/method hinting):

```
echo $post->comments[0]->author;
echo $post->comments[0]->contents;

```

Example
-------

[](#example-1)

We are using $rawData from example above, to build the same `\Blog\Post` object:

```
$otherPost = new \Blog\Post();
$metassione->fillObjectWithRawData($otherPost, $rawData);

print_r($otherPost);

```

which gives:

```
Blog\Post Object
(
    [title:Blog\Post:private] => il titolo
    [contents:Blog\Post:private] => Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Ut posuere risus eu commodo fermentum. Nullam nec dignissim est.
Curabitur adipiscing massa sit amet velit vehicula aliquam.
    [comments:Blog\Post:private] => Array
        (
            [0] => Blog\Comment Object
                (
                    [authorName:Blog\Comment:private] => l'autore 1
                    [contents:Blog\Comment:private] => Lorem ipsum
                )

            [1] => Blog\Comment Object
                (
                    [authorName:Blog\Comment:private] => l'autore 2
                    [contents:Blog\Comment:private] => dolor sit amet
                )

        )

)

```

Which is equal to our starting `$post` object.

why 'metassione'
================

[](#why-metassione)

1. METASSIONE
2. METAdati e di rifleSSIONE
3. metadati e di riflessione
4. translate to english: metadata and reflection

Building POPOs
==============

[](#building-popos)

To make Metassione work, you need to add typehinting and phpdocs to your classes.

Example:

```

```

available property types
------------------------

[](#available-property-types)

- basic types
    - `int` | `integer`
    - `string`
    - `float` | `double`
    - `bool` | `boolean`
- arrays of basic types
    - `int[]` | `integer[]`
    - `string[]`
    - `float[]` | `double[]`
    - `bool[]` | `boolean[]`
- classes
    - `FirstClass`
    - `OtherClass`
    - `\Foo\Bar\AnotherClass`
- array of classes (`array` is ignored in `array|Foobar[]` )
    - `FirstClass[]`
    - `OtherClass[]`
    - `\Foo\Bar\AnotherClass[]`

Changelog
=========

[](#changelog)

0.6.1 Updated tests to phpunit 5.4
----------------------------------

[](#061-updated-tests-to-phpunit-54)

0.6.0 Total rewrite
-------------------

[](#060-total-rewrite)

- `Metassione::fillObjectWithRawData($targetObject, stdClass $rawData)` returns `$targetObject`
    - This allows you to write: `$myObject = $metassione->fillObjectWithRawData(new MyKlass(), $rawData);`
    - without storing `new MyKlass()` in temporary variable
- Class metadata retrieval separated from filling the objects (`CachingClassDefinitionBuilder`)
    - Added caching class metadata (only in memory)
- Performance: ~20% slower than [JsonMapper](https://github.com/cweiske/jsonmapper), where metassione 0.4 was 100+% slower
- Improvement in properties handling
    - support for nullable properties (`integer|null`, `FooBar|null`)
    - missing or null value for properties
        - property value is set to `zero` value - for non-nullable properties
            - `integer` -&gt; 0
            - `float` -&gt; 0.0
            - `string` -&gt; ''
            - `boolean` -&gt; false
            - `SomeKlass` -&gt; `new SomeKlass()`
            - any array -&gt; `[]`
        - property value is set to null for *nullable* properties
            - `integer` -&gt; `null`
            - `float` -&gt; `null`
            - `string` -&gt; `null`
            - `boolean` -&gt; `null`
            - `SomeKlass` -&gt; `null`
            - any array -&gt; `[]` (**!!! WARNING: array typed property is always set to empty array, not null. by design**)
- casting values to proper type
    - example: property is of type integer, and `12.95` float is passed. Final object will contain `12` as its property value
- recognizing undefined properties - they will be filled with nulls. When type for property is specified in invalid way - it is treated as undefined and always will be filled with null values.
- still **no** support for importing classes from other namespaces (`use ACME\Foo\Bar` and then `/* @var Bar */`)

### Upgrading 0.4.0 -&gt; 0.6.0

[](#upgrading-040---060)

Metassione 0.6.0 is more strict when processing values for properties.

- If you allow nulls for your properties (`integer|null`) - be warned that metassione will set these values to `null` when there is no valid value for property.
- All properties of target class are processed. If no value is found for such property then it will be set to `zero value` or `null`
- In 0.4.0 you could set object to integer property - now it is impossible. Property will get value of 0.0 (or null).

0.4.0
-----

[](#040)

### Properties without full class name may be used.

[](#properties-without-full-class-name-may-be-used)

Example:

```

```

- `$firstChild` - has full classname specified. That classname will be used
- `$secondChild`
    - has juz `ChildKlass` specified. Attempt to load `NorthslopePL\Metassione\Tests\Examples\ChildKlass` will be made.
    - if `\ChildKlass` is found - it will be used
    - if not, then `NorthslopePL\Metassione\Tests\Examples\ChildKlass` will be used if found
    - else exception will be thrown
- `$thirdChild` - has full classname specified. That classname will be used.

This feature **will not work** with:

- with `use` (`use \Foo\Bar; ... @var Bar`)
- namespace aliases

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

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

Every ~63 days

Recently: every ~181 days

Total

13

Last Release

3602d ago

### Community

Maintainers

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

---

Top Contributors

[![drbonzo](https://avatars.githubusercontent.com/u/31528?v=4)](https://github.com/drbonzo "drbonzo (117 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/drbonzo-metassione/health.svg)

```
[![Health](https://phpackages.com/badges/drbonzo-metassione/health.svg)](https://phpackages.com/packages/drbonzo-metassione)
```

###  Alternatives

[ashallendesign/redactable-models

A Laravel package for easily redacting model data.

1143.4k](/packages/ashallendesign-redactable-models)[byrokrat/banking

Data types for accounts in the swedish banking system

1395.6k6](/packages/byrokrat-banking)[machy8/webloader

Simple, easy to use, php bundler for javascript and css

1934.2k3](/packages/machy8-webloader)[tobimori/kirby-tailwind-merge

Tailwind Merge for Kirby CMS

276.3k](/packages/tobimori-kirby-tailwind-merge)[imarc/craft-sass

A Craft plugin that compiles SASS on the server as needed.

145.8k](/packages/imarc-craft-sass)

PHPackages © 2026

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