Hi there,
Good day ! I have a question related to private variable in php class. I want to make check if someone accesses private variable, an exception is thrown says "this is private variable" and rest of the excecution of code didn't stop.
<?php
class myClass
{
public $str;
private $pinCode = 111;
}
//object
$ob = new myClass();
$ob -> str = "This is a string.";
//code before the exception
echo $ob -> str;
if(isset($ob -> pinCode))
{
throw new Exception("this is private variable");
}
try
{
echo $ob -> pinCode;
}
catch(Exception $e)
{
echo 'Message : ' .$e -> getMessage();
}
//code after the exception
$name = "abc <br />";
echo $name;
?>
I know if we access private variable it will give an error but I want not to stop the execution of the code after the exception. Looking forward for reply, Thanks !