Skip to content

Commit b0af549

Browse files
authored
Merge pull request #6 from Cheburon/CLOUD-11920-obfuscate-private-static-bug
static private property fixed
2 parents 94f054e + 9104497 commit b0af549

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateProperty.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ public function enterNode(Node $node)
8787
return $node;
8888
}
8989
}
90+
91+
if ($node instanceof Node\Expr\StaticPropertyFetch) {
92+
if ((string)$node->class !== "self") {
93+
return;
94+
}
95+
96+
if ($this->isRenamed($node->name)) {
97+
$node->name = $this->getNewName($node->name);
98+
return $node;
99+
}
100+
}
90101
}
91102

92103
/**

tests/before/SimpleClass.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ class SimpleClass {
44

55
const CONSTANT_VARIABLE = "test";
66

7-
static $staticProperty = "test";
7+
public static $publicStaticProperty = "test";
8+
protected static $protectedStaticProperty = "test";
9+
private static $_privateStaticProperty = "test";
10+
811

912
private $_privateProperty;
1013
protected $_protectedProperty;
@@ -15,6 +18,9 @@ private function _privateMethod() {
1518
$this->_privateProperty = $localVar;
1619
$this->_protectedProperty = $localVar;
1720
$this->publicProperty = $localVar;
21+
self::$publicStaticProperty = "test";
22+
self::$protectedStaticProperty = "test";
23+
self::$_privateStaticProperty = "test";
1824
}
1925

2026
protected function _protectedMethod() {

tests/expected/SimpleClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?php
2-
class SimpleClass { const CONSTANT_VARIABLE = "test"; static $staticProperty = "test"; private $sp8839d9; protected $_protectedProperty; public $publicProperty; private function sp51fa3f() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } protected function _protectedMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod();
2+
class SimpleClass { const CONSTANT_VARIABLE = "test"; public static $publicStaticProperty = "test"; protected static $protectedStaticProperty = "test"; private static $sp39db2b = "test"; private $sp8839d9; protected $_protectedProperty; public $publicProperty; private function sp51fa3f() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; self::$publicStaticProperty = "test"; self::$protectedStaticProperty = "test"; self::$sp39db2b = "test"; } protected function _protectedMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod();

0 commit comments

Comments
 (0)