Skip to content

Instantly share code, notes, and snippets.

@garex
Created June 30, 2017 08:51
Show Gist options
  • Save garex/5f8622413c34843dfa7286375824c6ee to your computer and use it in GitHub Desktop.
Save garex/5f8622413c34843dfa7286375824c6ee to your computer and use it in GitHub Desktop.
Typed collection with phpdoc
<?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