Last active
October 29, 2019 17:11
-
-
Save Shelob9/eaed968b6f8530d97cd9fcfc1054ef99 to your computer and use it in GitHub Desktop.
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 | |
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 | |
} | |
} | |
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 | |
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