PHP code example of matephp / dto

1. Go to this page and download the library: Download matephp/dto 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/ */

    

matephp / dto example snippets


use Mate\Dto\Dto;

class UserDto extends Dto
{
    public private(set) string $name;
    public private(set) int $age;
    public ?string $email = null;
}

// Instantiate from an array
$user = new UserDto([
    'name' => 'John Doe',
    'age' => 30,
    'email' => '[email protected]'
]);

echo $user->name; // John Doe
echo $user->toJson();
bash
composer