Skip to content

Commit 10658ae

Browse files
milodg
authored andcommitted
Respect final as literals [Closes #4]
1 parent b2ecbf4 commit 10658ae

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

src/BypassFinals.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private function native($func)
207207
public static function removeFinals($code)
208208
{
209209
if (strpos($code, 'final') !== false) {
210-
$tokens = token_get_all($code);
210+
$tokens = PHP_VERSION_ID >= 70000 ? token_get_all($code, TOKEN_PARSE) : token_get_all($code);
211211
$code = '';
212212
foreach ($tokens as $token) {
213213
$code .= is_array($token)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Tester\Assert;
4+
5+
require __DIR__ . '/../../vendor/autoload.php';
6+
7+
Tester\Environment::setup();
8+
9+
10+
DG\BypassFinals::enable();
11+
12+
require __DIR__ . '/fixtures/final.class.56.php';
13+
14+
$rc = new ReflectionClass('FinalClass56');
15+
Assert::false($rc->isFinal());
16+
Assert::false($rc->getMethod('finalMethod')->isFinal());

tests/BypassFinals/BypassFinals.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
22

3+
/**
4+
* @phpVersion 7
5+
*/
6+
37
use Tester\Assert;
48

59
require __DIR__ . '/../../vendor/autoload.php';
@@ -14,3 +18,5 @@ require __DIR__ . '/fixtures/final.class.php';
1418
$rc = new ReflectionClass('FinalClass');
1519
Assert::false($rc->isFinal());
1620
Assert::false($rc->getMethod('finalMethod')->isFinal());
21+
Assert::same(123, FinalClass::FINAL);
22+
Assert::same(456, (new FinalClass)->final());
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
final class FinalClass56
4+
{
5+
final function finalMethod()
6+
{
7+
}
8+
}

tests/BypassFinals/fixtures/final.class.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
final class FinalClass
44
{
5+
const FINAL = 123;
6+
57
final function finalMethod()
68
{
79
}
10+
11+
function final ()
12+
{
13+
return 456;
14+
}
815
}

0 commit comments

Comments
 (0)