In my class, I am trying to set the value of a variable in a function other than __construct()
But I need that variable value in another function.
Here is what I have tried. But not works Properly.
I expect to print getty images but I get nothing :(
<?php
class MyClass{
public $var;
public function __construct(){
$this->var;
}
public function setval(){
$this->var = 'getty Images';
}
public function printval(){
echo $this->var;
}
}
$test = new MyClass();
$test->printval();
getty imagesbut i get nothing :($this->var?