I am in a learning curve with PHP OOP
This is my code
file1.php
class A
{
public $id;
public $oop;
function __construct(){
$this->time=time();
}
}
$a = new A();
I tried to access the variable id
from a class B which is in another file, code given below.
file2.php
include('file1.php');
class B
{
function store(){
global $a; //question updated**
$x = 1;
$y = 1;
if($x == $y){
$a->id = $y; // I am setting a value for variable id.
}
}
}
$b = new B();
Now I want to access the variable id
in my index.php file as below.
index.php
require_once('file2.php');
$b->store(); // Store function executed ** question updated
echo $a->id;
The above code didn't throw me any error, the problem is the value I set for $id
isn't echoing.
I also referred some of the answers from here which is nearly similar
call variable from another function in class
how to call a variable from one class function to another class function
But didn't solve my problem.
Please, direct me to achieve my goal here.
Thank you.