Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active October 29, 2019 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/eaed968b6f8530d97cd9fcfc1054ef99 to your computer and use it in GitHub Desktop.
Save Shelob9/eaed968b6f8530d97cd9fcfc1054ef99 to your computer and use it in GitHub Desktop.
<?php
interface Item {
}
interface Collection {
/**
*
* @return $this
*/
public function addItem(Item $item );
}
class CollectionOne extends Collection{
public function addItem(Item $item )
{
$this->items[] = $item;
return $this;
}
}
class CollectionTwo extends Collection{
public function addItem(Item $item )
{
$this->items[] = $item;
return $item; // not correct but no compile time error is thrown
}
}
<?php
interface Item {
}
interface Collection {
public function addItem(Item $item ) : Item;
}
class CollectionConcrete extends Collection{
public function addItem(Item $item ) : Item
{
$this->items[] = $item;
return $this;
}
}
$collection = ( new CollectionConcrete7() )->addItem($i)->addItem($i2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment