Statement on glibc/iconv Vulnerability

UnitEnum インターフェイス

(PHP 8 >= 8.1.0)

はじめに

UnitEnum インターフェイスは、 全ての列挙型に対して、PHP のエンジンが自動的に適用するものです。 ユーザー定義のクラスとして実装してはいけません。 列挙型はメソッドのオーバーライドを禁止しています。 デフォルトの実装は PHP のエンジンから提供されるからです。 このインターフェイスは、型チェックのためだけに存在しています。

インターフェイス概要

interface UnitEnum {
/* メソッド */
public static cases(): array
}

目次

add a note

User Contributed Notes 1 note

up
-1
leonardosahon at gmail dot com (Osahenrumwen A)
8 months ago
When looping through cases, you will need to access the values as an object and not an array, like this:

<?php

enum BlogStatus : string {
case
Published = "is_published";
case
Draft = "is_draft";
case
Scheduled = "is_scheduled";
}

foreach (
BlogStatus::case() as $datum){
echo
$datum->name . '<br />'; // Published || Draft || Scheduled
echo $datum->value . '<br />'; // is_publised || is_draft || is_scheduled
}

?>
To Top