Skip to content

Commit

Permalink
Respect final as literals [Closes #4]
Browse files Browse the repository at this point in the history
  • Loading branch information
milo authored and dg committed Jul 20, 2018
1 parent b2ecbf4 commit 10658ae
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/BypassFinals.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private function native($func)
public static function removeFinals($code)
{
if (strpos($code, 'final') !== false) {
$tokens = token_get_all($code);
$tokens = PHP_VERSION_ID >= 70000 ? token_get_all($code, TOKEN_PARSE) : token_get_all($code);
$code = '';
foreach ($tokens as $token) {
$code .= is_array($token)
Expand Down
16 changes: 16 additions & 0 deletions tests/BypassFinals/BypassFinals.56.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Tester\Assert;

require __DIR__ . '/../../vendor/autoload.php';

Tester\Environment::setup();


DG\BypassFinals::enable();

require __DIR__ . '/fixtures/final.class.56.php';

$rc = new ReflectionClass('FinalClass56');
Assert::false($rc->isFinal());
Assert::false($rc->getMethod('finalMethod')->isFinal());
6 changes: 6 additions & 0 deletions tests/BypassFinals/BypassFinals.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* @phpVersion 7
*/

use Tester\Assert;

require __DIR__ . '/../../vendor/autoload.php';
Expand All @@ -14,3 +18,5 @@ require __DIR__ . '/fixtures/final.class.php';
$rc = new ReflectionClass('FinalClass');
Assert::false($rc->isFinal());
Assert::false($rc->getMethod('finalMethod')->isFinal());
Assert::same(123, FinalClass::FINAL);
Assert::same(456, (new FinalClass)->final());
8 changes: 8 additions & 0 deletions tests/BypassFinals/fixtures/final.class.56.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

final class FinalClass56
{
final function finalMethod()
{
}
}
7 changes: 7 additions & 0 deletions tests/BypassFinals/fixtures/final.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

final class FinalClass
{
const FINAL = 123;

final function finalMethod()
{
}

function final ()
{
return 456;
}
}

0 comments on commit 10658ae

Please sign in to comment.