This is my first question, and something which has got me stumped. I'm not sure if this is something simple and I'm overlooking it or something not possible.
Below is a very simplified version of my original code. The end goal is to have the output as follows:
1:
2: this is a test
3: this is another test
4: this is another test
However, with the code in its current state, its actual output is this:
1:
2: this is a test
3: this is another test
4:
I want object 'B' to be able to access the value of test_variable AFTER first_function() has altered it.
It works fine when I declare test_variable as static, however in the actual application it wouldn't work and when I try to echo parent::test_variable it outputs 'Object ID #17' and so on.
class A
{
public $test_variable;
function __construct()
{
echo '1: ' . $this->test_variable . "<br />";
$this->test_variable = 'this is a test';
echo '2: ' . $this->test_variable . "<br />";
}
function first_function()
{
$this->test_variable = 'This is another test';
echo '3: ' . $this->test_variable . "<br />";
$b = new b;
$b->second_function();
}
}
class B extends A
{
function __construct()
{
/* Dont call parent construct */
}
function second_function()
{
echo '4: ' . $this->test_variable;
}
}
$a = new A;
$a->first_function();
// Outputs:
// 1:
// 2: this is a test
// 3: this is another test
// 4:
// but I want it to output
// 1:
// 2: this is a test
// 3: this is another test
// 4: this is another test
Many thanks for any responses. I greatly appreciate them.
Phil