Hi, guys.
Here is my trouble, this code do not reacts like expected.
I expect the get_warning method to output 4 array, but it only output 3.
<?php
class formgen extends forminfo{
function formgen(){
$this->forminfo();
}
function applyform(){
$this->action->actions->doit();
}
}
class forminfo {
var $action;
var $fields;
var $warning;
var $myself;
function forminfo(){
$this->myself = & $this;
$this->action = new formaction();
$this->action->loadactions(& $this);
$this->fields = new fieldinfo();
$this->fields->init(& $this);
}
function addwarn($msg){
$this->warning[] = $msg;
}
function get_warning(){
//hmmmmm empty why?
echo 'INFO_WARN => <pre>';print_r($this->warning);echo '</pre>';
echo 'INFO_MYSELF_WARN => <pre>';print_r($this->myself->warning);echo '</pre>';
echo 'FIELD_WARN => <pre>';print_r($this->fields->infos->warning);echo '</pre>';
echo 'ACTION_WARN => <pre>';print_r($this->action->infos->warning);echo '</pre>';
}
}
class fieldinfo {
var $infos;
function fieldinfo(){}
function init(& $infos){
$this->infos = & $infos;
}
}
class formaction {
var $infos;
var $actions;
function formaction(){}
function loadactions(& $infos){
$this->infos = & $infos;
$this->actions = new DB_action();
$this->actions->init(& $infos );
}
}
class DB_action extends formaction {
function DB_action(){
$this->formaction();
}
function init(& $infos ){
$this->infos = & $infos;
}
function doit(){
$this->infos->addwarn('should be seen everywhere');
}
}
$obj = new formgen();
$obj->applyform();
$obj->get_warning();
?>
Here it looks, like only the refenced copy is updated by the addwarn call but not the original object that is the source of all ref copy.
Well, I can get arround this by doing something not really nice ( $this->myself = & $this ).
If someone, can explain me why $this->warning (in forminfo object) is empty.