1. Go to this page and download the library: Download kaasplootz/object-parser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kaasplootz / object-parser example snippets
namespace example;
use kaasplootz\objectParser\ObjectParser;
class SameName extends ObjectParser {}
class Friend extends ObjectParser {}
class User extends ObjectParser {
public function __construct(
public int $id,
public string $username,
private string $private,
public float $float,
public SameName $sameName,
public SameName $otherName,
public array $friends,
public ?string $nullable = null
) {}
public function getPrivate(): string
{
return $this->private;
}
}
$user = new User(
1,
'username',
'privateValue',
1.0,
new SameName(),
new SameName(),
[
new Friend()
]
);
echo $user->toJSON();