Handle order dependence in for loops
- by Matt
Hey all,
I'm making a templating system where I instantiate each tag using a foreach loop. The issue is that some of the tags rely on each other so, I'm wondering how to get around that ordering from the looping.
Here's an example:
Class A {
public $width;
__construct() {
$this->width = $B->width(); // Undefined! Or atleast not set yet..
}
}
Class B {
private $width;
__construct() {
$this->width = "500px";
}
__tostring() {
return "Hello World!";
}
}
Template.php
$tags = array("A", "B");
foreach ($tags as $tag) {
$TagObj[$tag] = new $tag();
}
echo $TagObj['A']->width; // Nadamundo!
I know this has applications elsewhere and I'm sure this has been solved before, if someone could enlighten me or point me in the right direction that'd be great!
Thanks!
Matt Mueler