Results of 1 - 1 of about 1 for fromLength (0.000 sec.)
- 列挙型と static メソッド | PHP 8.3 9414
- 列挙型と static メソッド 列挙型は、static メソッドを持つこともできます。 列挙型で static メソッドを使う主な理由は、 コンストラクタの代わりをさせるためです。たとえば、以下のようなものです: <?php enum Size { case Small ; case Medium ; case La
... rge ; public static function fromLength ( int $cm ): self { return match ( true ) { $cm < 50 => self :: Small , $cm < 100 => self :: Medium , default => self :: L ... arge , }; } } var_dump ( Size :: fromLength ( 50 )); static メソッドには public, private, protected が指定できますが、 列挙型では実際 private と protected は同じもので ...
-
https://man.mtool.work/php/8.3/language.enumerations.static-methods.html
PREV
1
NEXT