note 128783 added to language.enumerations.methods
| From: | iloveyii.yahoo.com via php-notes | Date: | Sun, 06 Aug 2023 18:57:12 +0000 |
| Subject: | note 128783 added to language.enumerations.methods | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220744@lists.php.net to get a copy of this message | ||
Just to complete the function shape in the above neat example:
<?php
interface Colorful
{
public function color(): string;
}
enum Suit implements Colorful
{
case Hearts;
case Diamonds;
case Clubs;
case Spades;
// Fulfills the interface contract.
public function color(): string
{
return match($this) {
Suit::Hearts, Suit::Diamonds => 'Red',
Suit::Clubs, Suit::Spades => 'Black',
};
}
// Not part of an interface; that's fine.
public function shape(): string
{
return match($this) {
Suit::Hearts => 'â¤ï¸',
Suit::Diamonds => 'ð',
Suit::Clubs => 'â£ï¸',
Suit::Spades => ' â ï¸'
};
}
}
echo Suit::Diamonds->shape();
echo PHP_EOL;
echo Suit::Clubs->shape();
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.157.134 (proxied: 2a00:1598:d6f1:fa00:d7:529a:e227:9620)
----
Manual Page -- https://php.net/manual/en/language.enumerations.methods.php
Edit -- https://main.php.net/note/edit/128783
Del: integrated -- https://main.php.net/note/delete/128783/integrated
Del: useless -- https://main.php.net/note/delete/128783/useless
Del: bad code -- https://main.php.net/note/delete/128783/bad+code
Del: spam -- https://main.php.net/note/delete/128783/spam
Del: non-english -- https://main.php.net/note/delete/128783/non-english
Del: in docs -- https://main.php.net/note/delete/128783/in+docs
Del: other reasons-- https://main.php.net/note/delete/128783
Reject -- https://main.php.net/note/reject/128783
Search -- https://main.php.net/manage/user-notes.php