Function redeclaration error, from another instance.
Posted: Wed Jan 12, 2005 6:46 pm
The following code gives the error "Fatal error: Cannot redeclare bar() (previously declared in /var/www/htdocs/tmp/tmp.php:6) in /var/www/htdocs/tmp/tmp.php on line 5"
I believed that the function bar() would be out of scope. Am I misunderstading something about scope?
Generally though what I need to do is have a function, nested inside a member function of a class, and be able to instantiate that class more than once in a script. Is this possible?
TIA,
Karl.
I believed that the function bar() would be out of scope. Am I misunderstading something about scope?
Generally though what I need to do is have a function, nested inside a member function of a class, and be able to instantiate that class more than once in a script. Is this possible?
TIA,
Karl.
Code: Select all
<?php
class foob{
function foo(){
function bar(){
echo "bar";
}
echo "foo";
bar();
}
function foo2(){
echo "foo2";
}
}
$foo = new foob();
$foo->foo(); // echos "foobar"
$foo->foo2(); // echos "foo2"
$foo2 = new foob();
$foo2->foo2(); // echos "foo2"
$foo2->foo(); // Fatal error
?>