ntlab / php-obj
A PHP object representation as string, javascript, annotation, or YAML
v1.8.1
2024-09-28 08:06 UTC
Requires
- php: >=7.2
Requires (Dev)
- phpunit/phpunit: ^8.5 || ^9.5
README
Represent PHP object as string, javascript, annotation, or YAML.
Examples
-
Represent PHP object as string
<?php use NTLAB\Object\PHP; $a = new PHP([1, 2, 3], ['inline' => true]); echo (string) $a; // [1, 2, 3] $a = new PHP(['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...'], ['inline' => true]); echo (string) $a; // ['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...']
-
Represent PHP object as annotation
<?php use NTLAB\Object\Annotation; $a = new Annotation(['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...'], ['annotation' => '@Fruit', 'inline' => true]); echo (string) $a; // @Fruit(name="Apple", color="Red", description="It's yummy...")
-
Represent PHP object as javascript
<?php use NTLAB\Object\JS; $a = new JS(['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...'], ['inline' => true]); echo (string) $a; // {name: 'Apple', color: 'Red', description: 'It\'s yummy...'}
- Represent PHP object as YAML
<?php use NTLAB\Object\YAML; $a = new YAML(['name' => 'Apple', 'color' => 'Red', 'description' => 'It\'s yummy...']); echo (string) $a; // name: // Apple // color: // Red // description: // It's yummy...