Req #71271 [Wfx]: Allow final abstract class {}
| From: | requinix@php.net | Date: | Mon, 04 Jan 2016 06:16:07 +0000 |
| Subject: | Req #71271 [Wfx]: Allow final abstract class {} | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-198393@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71271&edit=1
ID: 71271
Updated by: requinix@php.net
Reported by: andreas at dqxtech dot net
Summary: Allow final abstract class {}
Status: Wont fix
Type: Feature/Change Request
Package: Class/Object related
PHP Version: 7.0.2RC1
Block user comment: N
Private report: N
New Comment:
Original RFC thread: http://marc.info/?l=php-internals&m=141706013928872&w=2
Thread renamed: http://marc.info/?l=php-internals&m=141744239115034&w=2
Vote: http://marc.info/?l=php-internals&m=141840083023519&w=2
Your abstract+final idea was one of the options (the first one, even) but it looks like full static
classes had more support. After all, if you can't instantiate the class and you can't
extend it, what else can you do with it besides use static members?
You're free to bring up the subject on the internals list, naturally. However it's only
been a year so I wouldn't expect opinions to have changed much.
Previous Comments:
------------------------------------------------------------------------
[2016-01-04 05:50:48] andreas at dqxtech dot net
It seems this is the discussion:
https://github.com/php/php-src/pull/923
------------------------------------------------------------------------
[2016-01-04 05:43:10] andreas at dqxtech dot net
Is there any discussion I could have a look at, that explains why the RFC was discarded by most
participants?
Also, what I propose is not really the same, it is much simpler: Allow the combination of the two
keywords, with the regular natural consequences.
abstract: Cannot instantiate.
final: Cannot inherit.
I do NOT propose that a final + abstract class should only have static members.
I think it would be a bad idea to enforce this on the language level.
On the other hand, an IDE could very well notify people about the pointlessness of non-static
methods within a final abstract class.
Unlike the RFC, this simple proposal adds no confusion and no magic. Everything will behave as one
would expect.
------------------------------------------------------------------------
[2016-01-04 05:31:18] requinix@php.net
The idea was considered and declined. https://wiki.php.net/rfc/abstract_final_class
------------------------------------------------------------------------
[2016-01-04 05:21:15] andreas at dqxtech dot net
Description:
------------
It should be allowed to make a class both final and abstract, to make it a place for static methods.
There is no good reason to not allow this.
It is already possible to achieve the same or a similar effect with final + a private constructor.
But this is unnecessarily verbose.
Test script:
---------------
<?php
abstract final class C {
static function foo() {}
}
Expected result:
----------------
should work just fine.
Actual result:
--------------
Fatal error: Cannot use the final modifier on an abstract class
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71271&edit=1