<?php
class Foo{
public $basket;
public function __construct()
{
$this->basket = 1;
}
public function getBasket(){
return $this->basket;
}
}
class Bar{
public function __construct(&$basket)
{
$basket++;
}
}
$newFoo = new Foo();
$newBar = new Bar($newFoo->getBasket());
echo $newFoo->getBasket();
?>
I am hoping to initialise the $basket
value in one class and manipulate the same variable via another class. Unfortunately, I keep getting the "Notice: Only variables should be passed by reference in " error message.
Question: How can I change the code to make this happen? Thank you.