Hi All
I've been having all sorts of issues just trying to get a LIFO Stack working in PHP and am not quite sure why. In my latest incarnation I've actually build a Stack class. However, when I try to call the push function (and probably the pop too if it ever got that far) it just returns the following error:
When I call the stack's functions from the procedural code I have no problems, however when it is called from a function it won't work. I've tried declaring the class instance as global but that doesn't seem to work either. My code is below:
Any ideas much appreciated!
SenorCai
I've been having all sorts of issues just trying to get a LIFO Stack working in PHP and am not quite sure why. In my latest incarnation I've actually build a Stack class. However, when I try to call the push function (and probably the pop too if it ever got that far) it just returns the following error:
Code:
Fatal error: Call to a member function push() on a non-object in...
Code:
class LIFOStack{
var $elementData;
function LIFOStack(){
$this->elementData = array();
}
function pop(){
return array_pop($this->elementData);
}
function push($item) {
array_push($this->elementData, $item);
return $item;
}
}
global $stack;
$stack = new LIFOStack;
[b]$stack->push("hello");
echo($stack->pop()); //this returns 'hello' fine.[/b]
function startElement($parser, $name, $attribs){
if($name == "RESULT")
echo("<Property>");
else if(count($attribs)){
//echo("<$attribs['NAME']>"); - TODO: shouldn't we be able to do something like this?!
foreach ($attribs as $k => $v)
if($k == "NAME"){
echo("<$v>");
[b]$stack->push($v); //this always throws the error[/b]
}
}
}
SenorCai