prewk / serialized-to-ast
Parses serialized PHP things to an AST
Installs: 49
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/prewk/serialized-to-ast
Requires
- php: >=7.0
Requires (Dev)
- leanphp/phpspec-code-coverage: ^4.1
- phpspec/phpspec: ^4.3
- satooshi/php-coveralls: ^2.0
- vimeo/psalm: ^1.1
This package is auto-updated.
Last update: 2025-09-29 01:53:35 UTC
README
Parses serialized PHP data, without deserializing, into a simple AST.
Example
class Test { private $foo = "Private Foo"; public $bar = 12345; protected $baz = ["lorem", "ipsum" => "dolor amet", 67890]; } $parser = new Prewk\SerializedToAst; $node = $parser->parse(serialize(new Test)); // Array representation.. $arrayAst = $node->toArray(); // ..or JSON (see below) $jsonAst = json_encode($node);
{
"type": "object",
"public_properties": {
"bar": {
"type": "integer",
"value": 12345
}
},
"protected_properties": {
"baz": {
"type": "array",
"items": {
"0": {
"type": "string",
"value": "lorem"
},
"ipsum": {
"type": "string",
"value": "dolor amet"
},
"1": {
"type": "integer",
"value": 67890
}
}
}
},
"private_properties": {
"foo": {
"type": "string",
"value": "Private Foo"
}
}
}
Installation
composer require prewk/serialized-to-ast
Works for
- Booleans
- Integers
- Strings
- Floats
- Null
- Arrays
- Objects
Will cry if fed other stuff.
Warning: Experimental and not tested for edge cases.
License
MIT