class Concatenator
{
private static $string = [];
public static function __callStatic($method, $parameters)
{
self::$string = $parameters;
}
public function __toString()
{
return str_replace(' ', '+', strtolower(self::$string));
}
}
$concatenated = Concatenator::prepareString('I am concatenated');
echo $concatenated;
I can't figure out how to pass the value from the magic __callStatic() method to the magic __toString().
Please tell me what is wrong with the code? Why doesn't __toString() see self::$string?