1. Go to this page and download the library: Download ddn/jsonobject 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/ */
class Address extends TypedObjectSimple {
public string $street;
public int $number;
public string $city;
public string $country;
}
class User extends TypedObjectSimple {
public int $id;
public string $name;
public int $age;
public array $emails;
public ?Address $address;
}
class User extends TypedObject {
const ATTRIBUTES = [
'id' => 'int',
'name' => 'string',
'age',
'emails',
'address',
];
}
class Address extends TypedObjectSimple {
public string $street;
public int $number;
public string $city;
public string $country;
}
class User extends TypedObjectSimple {
public int $id;
public string $name;
public int $age;
public array $emails;
public ?Address $address;
}
class User extends TypedObject {
const ATTRIBUTES = [
'id' => [ 'string', 'generate_id' ],
'name' => [ 'string', 'John Doe' ],
];
function generate_id() {
return uniqid();
}
}
class User extends TypedObject {
const ATTRIBUTES = [
'id' => 'string',
'name' => 'string',
];
public $name = "John Doe";
public $id = "generate_id";
function generate_id() {
return uniqid();
}
}
class User extends TypedObject {
const ATTRIBUTES = [
'name' => 'string',
];
}
$user = new User();
echo($user->name);
class User extends TypedObject {
const ATTRIBUTES = [
'name' => 'string',
];
}
$user = new User();
if (!isset($user->name)) {
echo "Name has not been set";
}
echo $user->name??"Name has not been set";
$user = new User();
$user->name = "John Doe";
$user->type = 0; // This will work
$user->type = "user"; // This will work
$user->type = 1.0; // This will work
$user->type = true; // This will work