Removes final keyword from source code on-the-fly and allows mocking of final methods and classes

Installs: 6 727 208

Dependents: 256

Suggesters: 1

Security: 0

Stars: 344

Watchers: 12

Forks: 23

Open Issues: 0

v1.4.1 2022-09-13 17:27 UTC

This package is auto-updated.

Last update: 2023-03-13 18:31:08 UTC


Downloads this Month Tests Latest Stable Version License


Removes final keywords from source code on-the-fly and allows mocking of final methods and classes. It can be used together with any test tool such as PHPUnit, Mockery or Nette Tester.


The recommended way to install is through Composer:

composer require dg/bypass-finals --dev

It requires PHP version 7.1 and supports PHP up to 8.2.


Simply call this:


You need to enable it before the classes you want to remove the final are loaded. So call it as soon as possible, preferably right after vendor/autoload.php is loaded.

Note that final internal PHP classes like Closure cannot be mocked.

You can choose to only bypass finals in specific files or directories:


This gives you finer control and can solve issues with certain frameworks and libraries.

You can try to increase performance by using the cache (the directory must exist):

DG\BypassFinals::setCacheDirectory(__DIR__ . '/cache');

Support Project

Do you like BypassFinals?