Okay, so I’m trying to create a Call class on top of my Controller, Model and View. However, when I set the the class to the array inside the Call class, it seems to be stacking the arrays on top of one another (in the order that they are called), instead of putting them in order one by one.
Here’s what I mean:
array(1) {
["Controller"]=>
object(Controller)#2 (1) {
["classes"]=>
array(1) {
["Controller_Pages"]=>
object(Controller_Pages)#3 (1) {
["classes"]=>
array(1) {
["View"]=>
object(View)#4 (2) {
["params"]=>
array(2) {
["Testing"]=>
string(7) "a test."
["lolni"]=>
string(7) "a test."
}
["classes"]=>
array(0) {
}
}
}
}
}
}
}
It seems to be stacking them in the order that I am calling them.
Here’s the Call class:
<?php
class Call {
public $classes = Array();
public function __call($name, $args) {
if(!is_object($this->classes[$name])) {
require_once 'Slave/' . str_replace('_', '/', $name) . '.php';
$this->classes[$name] = new $name();
// to confirm that they are being stacked in the order they are being called
echo $name . "\n\n";
}
return $this->classes[$name];
}
public function dump() {
var_dump($this->classes);
}
}
So inside the Controller, for example, you’d call a class like this:
<?php
// Class -> Function
$this->Model()->query();
Here’s the source if you want to take a look:
http://joshfoskett.com/View/Call_Issue
So the question is, how would I get the array to look like this?
array(3) {
["Controller"]=>
object(Controller)#1 (1) {
["classes"]=>
array(0) {
}
}
[0]=>
object(Controller_Pages)#2 (1) {
["classes"]=>
array(0) {
}
}
["View"]=>
object(View)#3 (2) {
["params"]=>
NULL
["classes"]=>
array(0) {
}
}
}
Incase someone references this later, here is what I did to solve the issue.
I basically set
$classestostatic, and referenced the classes withself:::This way, the class that extends to
Callisn’t using$this->classeson it’s own.