Created
December 2, 2016 13:43
-
-
Save alexbowers/9520c8df746249ecae2d9c7aad2e54ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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