Created
June 30, 2017 08:51
-
-
Save garex/5f8622413c34843dfa7286375824c6ee to your computer and use it in GitHub Desktop.
Typed collection with phpdoc
This file contains 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 | |
// @see https://www.sitepoint.com/creating-strictly-typed-arrays-collections-php/ | |
class Wtf | |
{ | |
public function wow() | |
{ | |
echo __METHOD__; | |
} | |
} | |
class WtfCollection implements Iterator | |
{ | |
public function __construct(Wtf ...$values) | |
{ | |
$this->values = $values; | |
} | |
public function current(): Wtf {} | |
public function next() | |
{} | |
public function valid() | |
{} | |
public function rewind() | |
{} | |
public function key() | |
{} | |
} | |
$many = new WtfCollection(new Wtf()); | |
foreach ($many as $one) { | |
$one->wow(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment