Re: [IDEA] allow extending enum

From: Date: Wed, 29 Mar 2023 21:10:08 +0000
Subject: Re: [IDEA] allow extending enum
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-119782@lists.php.net to get a copy of this message
On Wed, Mar 29, 2023, at 4:28 PM, Mark Baker wrote: > Another benefit of this approach would be to allow the inclusion of > multiple enums, in the same way that we can include multiple traits. > > > enum HttpErrors { > >     case HTTP_STATUS_400; > >     case HTTP_STATUS_401; > >      … > > } > > enum DatabaseErrors { > >     case RECORD_NOT_FOUND; >     case DATABASE_NOT_AVAILABLE; > >      … > > } > > > > enum ApiErrors { > >     use HttpErrors, DatabaseErrors; > > > >     case JsonParserError; > >     case GraphQLParserError; > > } All that said, we could get the same functionality with fewer questions if we just finally got around to introducing type definitions. type ApiError = DatabaseError|HttpError; function handleErrors(ApiError $error) {...} That would obviate the need for a lot of workarounds. --Larry Garfield

« previous php.internals (#119782) next »