Bug #81293 [NEW]: Abstract method cases() in trait imoses contract upon the exhibiting enum

From: Date: Sun, 25 Jul 2021 15:43:03 +0000
Subject: Bug #81293 [NEW]: Abstract method cases() in trait imoses contract upon the exhibiting enum
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235336@lists.php.net to get a copy of this message
From:             raincomplain at outlook dot com
Operating system: 
PHP version:      8.1.0beta1
Package:          Class/Object related
Bug Type:         Bug
Bug description:Abstract method cases() in trait imoses contract upon the exhibiting enum

Description:
------------
Both Pure Enums and Backed Enums implement an internal interface named
UnitEnum. UnitEnum includes a static method cases(). So manually
defining cases() method on an Enum results in a fatal error as
expected(as clarified in enum RFC). However, it seems it's allowed to
define cases() in a trait, resulting in cases() being a requirment in
the exhibiting enum with somewhat a confused error which makes no
sense!. I think we should clarify with a proper error message that
abstract cases() is not allowed too. Non-abstract cases() is totally
fine since the enum implementation will take precedance over trait so no
error message is needed here.

Test script:
---------------
enum Size: int 
{
    use Test;
}

trait Test 
{
    abstract static private function cases(): int;
}

Expected result:
----------------
PHP Fatal error:  Abstract Size::cases() is already implemented

Actual result:
--------------
PHP Fatal error:  Declaration of Size::cases(): array must be compatible
with Test::cases(): int in /var/www/html/index.php on line 0

-- 
Edit bug report at https://bugs.php.net/bug.php?id=81293&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=81293&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=81293&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=81293&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=81293&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=81293&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=81293&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=81293&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=81293&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=81293&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=81293&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81293&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=81293&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=81293&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=81293&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=81293&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=81293&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=81293&r=mysqlcfg


Thread (6 messages)

« previous php.bugs (#235336) next »