Why as e ob_start't see a class variable?

The problem is this, I want before sending the content to add styles and scripts in head, the logic is simple, do:
str_replace('</head>', $this->links. '</head>', $buffer);

But he doesn't see the variable class, if you manually enter something like:
str_replace('</head>', '<script type="text/javascript" src="/js/jquery.js"></script></head>', $buffer);

Then everything is OK. In a variable everything is OK, if it thadaniti, the styles and scripts are, but it is in the callback not work :s

Processing class:
class GeneralClass
{
 private $links;

 function __construct() {
 ob_start(array('self', 'pageAssembly'));
}

 public function includeComponent($name, $template)
{
 if ($template === "") $template = "default";

 $defPath = "/core/components/";

 $this->links .= '<link rel="stylesheet" href="' . $defPath . $name . '/templates/' . $template . '/style.css">';
 $this->links .= '<script type="text/javascript" src="' . $defPath . $name . '/templates/' . $template . '/script.js"></script>';

 include_once $defPath . $name . "/templates/" . $template . "/template.php";
}

 private function pageAssembly($buffer) {
 return str_replace('</head>', $this->links. '</head>', $buffer);
}
}
April 19th 20 at 12:13
1 answer
April 19th 20 at 12:15
Solution
Some of sufixes. This thing ONLY works with static data, callback in ob_start sees only static...
Hours figuring out... In the documentation I couldn't find a behavior callback in ob_start
Here's how it works:
class GeneralClass
{
 static private $links;

 function __construct() {
 ob_start(array("self", "pageAssembly"));
}

 public function includeComponent($name, $template)
{
 if ($template === "") $template = "default";

 $defPath = "/core/components/";

 self::$links .= '<link rel="stylesheet" href="' . $defPath . $name . '/templates/' . $template . '/style.css">';
 self::$links .= '<script type="text/javascript" src="' . $defPath . $name . '/templates/' . $template . '/script.js"></script>';

 include_once $defPath . $name . "/templates/" . $template . "/template.php";
}

 public function pageAssembly($buffer) {
 return str_replace('</head>', self::$links . '</head>', $buffer);
}
}
This thing ONLY works with static data


Actually, no. Just you have to code it as a static context. It hurt to do normal?
ob_start([$this, 'pageAssembly']);

And if someone (we will not point fingers) have included the error output immediately about it would know. But someone (again, we omit the time with a finger) cut off their nafig, in this and enjoys challenges) - Chelsie.Man commented on April 19th 20 at 12:18
@Chelsie.Man, I love self-flagellation) - Raheem_Berni commented on April 19th 20 at 12:21

Find more questions by tags PHP