Idea: Inline enum

From: Date: Thu, 19 Dec 2024 17:11:54 +0000
Subject: Idea: Inline enum
Groups: php.internals 
Request: Send a blank email to internals+get-126139@lists.php.net to get a copy of this message
Hi all, I got a case where I have to create multiple different formatters and also I want to define the possible tokens of each formatter accessible in specific groups using enums. During that task I'm wondering why it's not possible to create an inline enum definition similar to an anonymous class object? Example: class MyFormatter {
    public const DATE_TOKEN = enum:string {
        case DayOfMonth = 'j';
        // ...
    };
    public const TIME_TOKEN = enum:string {
        case Hour = 'h';
        // ...
    };
} class AnotherFormatter {
    public const DATE_TOKEN = enum:string {
        case DayOfMonth = 'd';
        // ...
    };
    public const TIME_TOKEN = enum:string {
        case Hour = 'h';
        // ...
    };
} $token = MyFormatter::DATE_TOKEN::DayOfMonth; $token instanceof MyFormatter::DATE_TOKEN; What do you think?    Does that make sense?    Is that implementable? Marc

Attachment: [application/pgp-keys] OpenPGP public key OpenPGP_0x3936ABF753BC88CE.asc
Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc
« previous php.internals (#126139) next »