This is not in PHP itself, but Laravel has an interface designed for this purpose:
<?php namespace Illuminate\Contracts\Support; interface Arrayable { public function toArray(); }
Note: In Laravel v4, the namespace was Illuminate\Support\Contracts , and the interface name was ArrayableInterface .
coatesap
source share