Getting Started

Installation

Install using Composer:

composer require astral/php-serialize

Basic Usage

use Astral\Serialize\Serialize;

class User extends Serialize {
    public string $name,
    public int $age
}

// Create object from array
$user = User::from([
    'name' => 'John Doe',
    'age' => 30
]);

// Access object properties
echo $user->name;  // Output: John Doe
echo $user->age;   // Output: 30

// Convert to array
$userArray = $user->toArray();
// $userArray contents:
// [
//     'name' => 'John Doe',
//     'age' => 30
// ]

Other Features

  1. Immutability: Read-only properties cannot be modified after construction

  1. Type-Safe Initialization

  1. Constructor Initialization

最后更新于