PHP Fatal error: Call to a member function encode() on a non-object
-
Hello
Today I was try to install and using insert-php plugin in the first time.
However, I found a problem when I try to put a custom class that I provide into functions.php name ‘Encryption’ and a code was following:
class Encryption { var $skey = 'Key2015'; // you can change it public function safe_b64encode($string) { $data = base64_encode($string); $data = str_replace(array('+','/','='),array('-','_',''),$data); return $data; } public function safe_b64decode($string) { $data = str_replace(array('-','_'),array('+','/'),$string); $mod4 = strlen($data) % 4; if ($mod4) { $data .= substr('====', $mod4); } return base64_decode($data); } public function encode($value){ if(!$value){return false;} $text = $value; $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->skey, $text, MCRYPT_MODE_ECB, $iv); return trim($this->safe_b64encode($crypttext)); } public function decode($value){ if(!$value){return false;} $crypttext = $this->safe_b64decode($value); $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->skey, $crypttext, MCRYPT_MODE_ECB, $iv); return strtolower(trim($decrypttext)); } } $enc = new Encryption();
After that I want to use $enc function to call encode() in a post. So, I put a php code between [insert_php]…[/insert_php] like [insert_php]echo $enc->encode(number);[/insert_php]
However after I publish and view post. It was error as blank page with no information and I notice it was generate error_log following:
[12-Mar-2015 16:54:14 UTC] PHP Fatal error: Call to a member function encode() on a non-object in /home/…/wp-content/plugins/insert-php/insert_php.php(47) : eval()’d code on line 1
Can I solved this problem?
P.S. class Encryption() working if put directly into any php page such header.php but not working when try to using in a post with [insert_php]…[/insert_php]
Thank you
- The topic ‘PHP Fatal error: Call to a member function encode() on a non-object’ is closed to new replies.