Problem statement:
I have to pass a php object from one php application to another using json. In my destination application, I am not able to access my member functions after json_decode.
Here is the sample script:
<?php
class TestScope{
private $privateVar;
function __construct(){
$this->privateVar="private";
}
function getPrivateVar(){
return $this->privateVar;
}
}
$testScope = new TestScope();
$encode = json_encode($testScope);
$decode = json_decode($encode);
print_r($decode->getPrivateVar());
?>
After executing the script, I am getting below error:
PHP Fatal error: Call to undefined method stdClass::getPrivateVar()
What is the possible solution to prevent this error?