linked list, arrays and references to objects ???
Posted: Tue Jul 23, 2002 8:23 am
Hi
back again - I'm scratching my head again here ..
I am using a design pattern known as intercepting filter which is based on a simple linked list .
when I instantiate my filterroot I send an array of other concrete filters and the constructor iterates through them and sets the _childFilter and _hasChild attributes acordingly in a simple while loop
I then call the first execute to start the chain which should walk the app through the filterchain until finally returning to the root caller with my html response ..
this is done by each execute method inside a concrete InterceptingFilter class first checks whether it has a child filter then calls its execute method
eg
now this is all working fine until I reach the last but branch node which should point to my frontcontroller in its childfilter attribute .. but instead its child is left dangling at null and I get an error as I try to call a method on a null reference basically .. I gone through it loads of times trying to figure how I've buggered it up but am at a loss ..
the offending snippet is below
when debugging I have checked that its child is set properly with a reference to my frontcontroller and it seems to set just fine when I check in the root constructor but when this line executes it always falls over with ..
Fatal error: Call to a member function on a non-object in C:\Documents and Settings\ant\My Documents\objectmonkey_source\ViewFilter.php on line 13
if any of you have any ideas where I am going wrong it would be very greatly appreciated .. thanks
back again - I'm scratching my head again here ..
I am using a design pattern known as intercepting filter which is based on a simple linked list .
when I instantiate my filterroot I send an array of other concrete filters and the constructor iterates through them and sets the _childFilter and _hasChild attributes acordingly in a simple while loop
Code: Select all
class FilterChainRoot
{
var $_filters;
function FilterChainRoot($filters)
{
//iterate through the InterceptingFilter array and
//add them to the chain of filters to execute
$this->_filters =& $filters;
$count = count($this->_filters);
$index = 0;
while ($index <= ($count - 1)):
if ($index > 0)
{
$tmp =& $this->_filtersї$index - 1];
$tmp->setChild($filtersї$index]);
//debug <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>
//echo get_class($tmp)." child is set as - ".get_class($tmp->getChild())."<br>";
}
$index++;
endwhile;
}
function execute($args)
{
//perform first execute in our chain
//each filter in the chain will check whether
//it has a child .. if so it will apss on its
//execute down the chain
$tmp = $this->_filtersї0];
return $tmp->execute($args);
}
}this is done by each execute method inside a concrete InterceptingFilter class first checks whether it has a child filter then calls its execute method
eg
Code: Select all
...
if ($this->_hasChild)
{
$tmp =& $this->_childFilter;
return $tmp->execute($arg);
}
...the offending snippet is below
Code: Select all
...
$obj =& $this->_childFilter;
$response = $obj->execute($args);Fatal error: Call to a member function on a non-object in C:\Documents and Settings\ant\My Documents\objectmonkey_source\ViewFilter.php on line 13
if any of you have any ideas where I am going wrong it would be very greatly appreciated .. thanks