I'm sure I read a while back about a new feature of PHP that was either a new magic method or a new interface so that you could implement Arrayable methods.
eg
interface Arrayable
{
public function toArray();
}
Was I imagining it?
It's not in PHP itself, but Laravel has an interface that is intended for that exact purpose:
<?php namespace Illuminate\Contracts\Support;
interface Arrayable {
/**
* Get the instance as an array.
*
* @return array
*/
public function toArray();
}
Note: In Laravel v4 the namespace was Illuminate\Support\Contracts
and the interface name was ArrayableInterface
.