I want to change value of variable that was called before but should be changed after it. Like in this exapmle:
<img src="<?php echo $src; ?>" />
$src = 'some_src.jpg';
Maybe some kind of buffering or something? That should be done this way, cause I'm trying to make a kind of template engine:
$this->showHeader();
$this->showBody();
But the body is in another file. In this file i would call:
$this->header->setScript('somescript.js');
And that should change variables in header. But I can't call showBody() function before showHeader(). Sorry for my english. :(
You cannot declare a variable after you call it. You will want to look at writing this in a different way like adding it a function attribute or some method of setting it properly before echoing it.
I've found the way to do this. Buffering was the way to accomplish my task.
I couldn,t echo body of page before the head, but I had to call body before head to collect possible variables changes. So I've put the content of body to a buffer:
ob_start();
$this->showBody();
$content = ob_get_clean();
Now I've collected variables values and I could use them:
$this->showHeader();
echo $content;
Pretty simple.