{"id":5892386,"date":"2015-03-12T18:14:58","date_gmt":"2015-03-12T18:14:58","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/php-fatal-error-call-to-a-member-function-encode-on-a-non-object\/"},"modified":"2016-08-22T17:58:42","modified_gmt":"2016-08-22T17:58:42","slug":"php-fatal-error-call-to-a-member-function-encode-on-a-non-object","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/php-fatal-error-call-to-a-member-function-encode-on-a-non-object\/","title":{"rendered":"PHP Fatal error:  Call to a member function encode() on a non-object"},"content":{"rendered":"<p>Hello<\/p>\n<p>Today I was try to install and using insert-php plugin in the first time.<\/p>\n<p>However, I found a problem when I try to put a custom class that I provide into functions.php name &#8216;Encryption&#8217; and a code was following:<\/p>\n<pre><code>class Encryption {\n    var $skey     = &#039;Key2015&#039;; \/\/ you can change it\n\n    public function safe_b64encode($string) {\n\n        $data = base64_encode($string);\n        $data = str_replace(array(&#039;+&#039;,&#039;\/&#039;,&#039;=&#039;),array(&#039;-&#039;,&#039;_&#039;,&#039;&#039;),$data);\n        return $data;\n    }\n\n    public function safe_b64decode($string) {\n        $data = str_replace(array(&#039;-&#039;,&#039;_&#039;),array(&#039;+&#039;,&#039;\/&#039;),$string);\n        $mod4 = strlen($data) % 4;\n        if ($mod4) {\n            $data .= substr(&#039;====&#039;, $mod4);\n        }\n        return base64_decode($data);\n    }\n\n    public function encode($value){\n\n        if(!$value){return false;}\n        $text = $value;\n        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);\n        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);\n        $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this-&gt;skey, $text, MCRYPT_MODE_ECB, $iv);\n        return trim($this-&gt;safe_b64encode($crypttext));\n    }\n\n    public function decode($value){\n\n        if(!$value){return false;}\n        $crypttext = $this-&gt;safe_b64decode($value);\n        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);\n        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);\n        $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this-&gt;skey, $crypttext, MCRYPT_MODE_ECB, $iv);\n        return strtolower(trim($decrypttext));\n    }\n}\n\n$enc = new Encryption();<\/code><\/pre>\n<p>After that I want to use $enc function to call encode() in a post. So, I put a php code between [insert_php]&#8230;[\/insert_php] like  [insert_php]echo $enc-&gt;encode(number);[\/insert_php]<\/p>\n<p>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:<\/p>\n<p>[12-Mar-2015 16:54:14 UTC] PHP Fatal error:  Call to a member function encode() on a non-object in \/home\/&#8230;\/wp-content\/plugins\/insert-php\/insert_php.php(47) : eval()&#8217;d code on line 1<\/p>\n<p>Can I solved this problem?<\/p>\n<p>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]&#8230;[\/insert_php]<\/p>\n<p>Thank you<\/p>\n<p>https:\/\/wordpress.org\/plugins\/insert-php\/<\/p>\n","protected":false},"template":"","class_list":["post-5892386","topic","type-topic","status-closed","hentry","topic-tag-class","topic-tag-php"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5892386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5892386\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=5892386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}