Skip to content

Instantly share code, notes, and snippets.

@alexbowers
Created December 2, 2016 13:43
Show Gist options
  • Save alexbowers/9520c8df746249ecae2d9c7aad2e54ae to your computer and use it in GitHub Desktop.
Save alexbowers/9520c8df746249ecae2d9c7aad2e54ae to your computer and use it in GitHub Desktop.
<?php
class Collection implements ArrayAccess, Arrayable, ...
{
protected $items = [];
public function __construct(array $items = [])
{
$this->items = $items;
}
...
public function __cast(array $items)
{
return new static($items);
}
}
public function convert_me(Collection $items)
{
var_dump($items);
}
$collection = new Collection([1,2,3]);
convert_me($collection);
convert_me([1,2,3]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment