<?php
class Main {
var $x = 3;
function a(){
$this->Child = new Child(&$this);
}
}
class Child {
function Child(&$m){
print $m->x;
}
}
$Main = new Main();
$Main->a();
?>$this->Child = new Child(&$this);
class Main {
protected $number = 3;
public function create($class) {
if (class_exists($class)) {
$this->$class = new $class($this);
}
return $this->$class;
}
public function getNumber() {
return $this->number;
}
}
class Child {
function __construct(Main &$main) {
$this->main =& $main;
print $this->main->getNumber();
}
}
$main = new Main();
$main->create('Child');
class SOME_CONFIG {
var $x = 'something';
}$config['x'] = 'something';
Well, using a reference to a Main class from the Child class is not actually inheritance; it’s a reference. But generally, I would have an array parameter as part of the constructor for any class that could take any number of optional arguments. You can deal with them in the constructor of your class or save them as passed into a variable of your class for access by class methods.
One more question... if you want to pass additional arguments to the class, how do you do that when you’ve got that inheritance thing going on in there.
Does what method work for "extending" the $modx object? I’m confused since there is no extending going on here...
Does this method work for extending the $modx object? (Versions 1 and earlier).