I am trying to learn oop and I'm trying to pass a value from one one function to another inside a class but for some reason it gives me an error of Notice: Trying to get property of non-object, any ideas?
class test{
function test($value){
global $db;
$stmt = $db->prepare("SELECT * FROM some_table where some_column = ?");
$stmt->bind_param('s', $value);
$stmt->execute();
$res = $stmt->get_result();
$fetch = $res->fetch_object();
$this->test = $fetch->some_row;//this is the error line
}
function do_something(){
$name = $this->test;
return $name;
}
}
$p = new test();
$p->test('test');
echo $p->do_something();
var_dump()and check the actual variable value.NULL, which is nonsense.$valueis the prob, if I give it some other value for the bind_param it works. Do you have any idea why the value forfunction test()not passing?