CascadiaPHP 2024

UnitEnum arayüzü

(PHP 8 >= 8.1.0)

Giriş

UnitEnum arayüzü tüm sayılamalara motor tarafından özdevinimsel uygulanır. Kullanıcı tanımlı sınıflarla gerçeklenemez. Öntanımlı olarak motor tarafından sağlanan yöntemlerini sayılamalar geçersiz kılamaz. Yalnızca tür sınamaları için kullanılabilir.

Arayüz Sözdizimi

interface UnitEnum {
/* Yöntemler */
public static cases(): array
}

İçindekiler

add a note

User Contributed Notes 2 notes

up
0
KhaledChebat at hotmail dot com
7 days ago
Example provided has a small typo.

It states 'case()' where the correct method is 'cases()'.
up
-4
leonardosahon at gmail dot com (Osahenrumwen A)
10 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