polidog / object-to-array
php object to array
Installs: 23 717
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 0
Forks: 1
Open Issues: 0
Requires
- php: >=7.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- phpunit/phpunit: ^9.5
README
object-to-array is simple convert PHP object to array.
Installation
$ composer require polidog/object-to-array
Usage
<?php
use function Polidog\ObjectToArray\object_to_array;
$date = new \DateTime();
$dateArray = object_to_array($data);
var_dump($dataArray);
Trait
<?php
use Polidog\ObjectToArray\ToArrayTrait;
class User
{
use ToArrayTrait;
private int $id;
private string $name;
private \DateTimeInterface $createdAt;
/**
* User constructor.
* @param int $id
* @param string $name
*/
public function __construct(int $id, string $name)
{
$this->id = $id;
$this->name = $name;
$this->createdAt = new \DateTime();
}
}
$user = new User(1, 'polidog');
var_dump($user->__toArray());