Created
August 27, 2023 21:30
-
-
Save wesllycode/4cf96a07733497ee1f44afa35f3a7c47 to your computer and use it in GitHub Desktop.
Explicando o usado da interface com trait. Se observar, eu declarei o método que interface pedi na trait e como trait é chamado dentro da classe Concert.php, por isso não dar erro de falta de implementação do método getPrice().
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 | |
require_once 'src/HasMenu.php'; | |
class Concert implements PricingContract | |
{ | |
use HasMenu; | |
public function __construct() | |
{ | |
$this->itens = [ | |
'Beer', | |
'Ale', | |
'Nachos' | |
]; | |
} | |
} |
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 | |
require_once 'src/Concert.php'; | |
$concert = new Concert(); | |
print_r($concert->getMenu()); |
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 | |
interface PricingContract | |
{ | |
public function getPrice(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment