I'm having issues with getter and setter functions in PHP. Following is how I have written my PHP classes.
--------------------------------------------------------------------------------------------------------------------
File1.php
--------------------------------------------------------------------------------------------------------------------
<?php
class TestClass1 {
private $var;
public function get_varvalue() {
return $this->var;
}
public function set_varvalue($TestVar) {
$this->var = $TestVar;
}
}
?>
--------------------------------------------------------------------------------------------------------------------
File2.php
--------------------------------------------------------------------------------------------------------------------
<?php
$obj = new TestClass1();
$obj->set_varvalue("someText");
?>
--------------------------------------------------------------------------------------------------------------------
File3.php
--------------------------------------------------------------------------------------------------------------------
<?php
class TestClass2 {
$obj2 = new TestClass1();
echo $obj2->get_varvalue();
}
?>
File1, File2 and File 3 are separate PHP files. File2 uses the TestClass1 object to set the value to variable 'var' but when I try to get the value print the value in File3.php by creating an object for the same class and calling the get_varvalue() function, I'm getting a blank output.
Please help me to solve this issue.
Thank you.
Regards,
tab4trouble