Reputation: 161
How can i encrypt a function or its contents in a php class ?
e.g. Take a look at below class, i would like to encrypt the function test1() so the code inside will never be revealed but executes as normal
class test
{
var $x;
var $y;
function test1()
{
return $this->x;
}
function test2()
{
return $this->y;
}
}
Thanks in advance
Upvotes: 1
Views: 101
Reputation: 5291
Extract test1 to base class:
abstract class testBase {
function test1(){
return $this->x;
}
}
Encode it with http://www.zend.com/en/products/guard/. Then use testBase as test parent:
class test extends testBase {
public $x;
public $y;
function test2(){
return $this->y;
}
}
Upvotes: 0
Reputation: 16230
The code can't really be hidden from someone that has access to the file, but it can be obfuscated. There are too many alternatives, try google 'php obfuscate'.
Keep in mind that even though it will be harder, it will by no means be impossible for a skilled coder to quickly discern what happens in your code (especially if it's as simple as the example you provided).
Upvotes: 3