Req #65119 [Opn->Wfx]: provide a way to inherit a final class or overriding final methods

From: Date: Tue, 29 Oct 2019 15:02:54 +0000
Subject: Req #65119 [Opn->Wfx]: provide a way to inherit a final class or overriding final methods
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223505@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65119&edit=1

 ID:                 65119
 Updated by:         requinix@php.net
 Reported by:        knight at kopernet dot org
 Summary:            provide a way to inherit a final class or overriding
                     final methods
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Reflection related
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Reflection allows calling private and protected members because that can be done at runtime.
Creating a new class/method that extends a final parent happens at compile-time; the only way to
bypass it would be to modify the class data in memory before the child class is loaded, and that is
more of a "runkit" operation than a reflection operation.

If you've written a lot of tests then you know that sometimes you have to refactor the source
to make testing possible. This is one of those times.


Previous Comments:
------------------------------------------------------------------------
[2019-10-29 14:27:51] ayg at aryeh dot name

This causes a significant limitation in PHPUnit (and presumably other unit-testing frameworks). It
is not possible to mock final classes or methods: <https://phpunit.readthedocs.io/en/8.3/test-doubles.html>.
(Mocking a class subclasses it and overrides the methods to be mocked, which doesn't work if
they're final.) This makes it difficult to write unit tests for code that uses final classes or
methods.

Someone went so far as to write a library that strips "final" from all PHP code to work
around this problem: <https://github.com/dg/bypass-finals>

This feature would be useful for MediaWiki, see discussion (we actually want to try using that
final-stripping library for test runs to work around the problem):

https://lists.wikimedia.org/pipermail/wikitech-l/2019-August/092432.html
https://phabricator.wikimedia.org/T231419

------------------------------------------------------------------------
[2013-06-25 08:04:10] knight at kopernet dot org

Description:
------------
Please provide a way to make possible to bypass the final keyword restriction in similar way the
ReflectionAPI makes possible to call private or protected members.



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=65119&edit=1


Thread (3 messages)

« previous php.bugs (#223505) next »