Hi Davey
On 29.03.23 16:31, Davey Shafik wrote:
The issue of contention here is that inheritance isn't the correct mechanism for reusing
enum definitions to expand on them. What about allowing "use" syntax like
traits?
enum HttpErrors {
case HTTP_STATUS_400;
case HTTP_STATUS_401;
…
}
enum ApiErrors {
use HttpErrors;
case JsonParserError;
case GraphQLParserError;
}
Now you have ApiErrors::HTTP_STATUS_400 etc without ApiErrors being is-a
HttpErrors.
This would still require making ApiErrors a supertype of HttpErrors so
that a parameter typed as ApiErrors accepts a
HttpErrors::HTTP_STATUS_400 value. This essentially mimicks implicit
multiple inheritance. The fact that these are implicit (for HttpErrors,
that is) makes this quite confusing, and difficult to implement
technically (usually classes are "locked" after linking). I would much
prefer the previously suggested approaches (using algebraic data types,
a.k.a. tagged unions, or union types of two enums).
Ilija
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php