Bug #10790 Updated: Cannot redeclare function/class from included file
| From: | sniper@php.net | Date: | Thu, 10 May 2001 15:50:27 +0000 |
| Subject: | Bug #10790 Updated: Cannot redeclare function/class from included file | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-54736@lists.php.net to get a copy of this message | ||
ID: 10790
Updated by: sniper
Reported By: christian.huff@silur.de
Old-Status: Open
Status: Feedback
Bug Type: Scripting Engine problem
Operating system:
PHP Version: 4.0.5
Assigned To:
Comments:
What if you use include_once() instead of include() ?
Does it make any difference?
--Jani
Previous Comments:
---------------------------------------------------------------------------
[2001-05-10 10:57:59] christian.huff@silur.de
Now this is what happens: I include a .php-file for database access via ODBC. While I was trying to
make things 'easier', I stumbled across a problem: Classes and functions declared in an
included file seem to work at first glance, but when reloaded, the declaration fails:
Fatal error: Cannot redeclare class odbc_obj in E:Web-ProjekteTestodbc.php on line 5
If I move the declaration of the class into the index.php, the script complains about being unable
to redeclare connexecute(). Reloading again after the error, the script works, but thereafter, it
refuses again and so on and on.
--- odbc.php ---
$conn_id = odbc_pconnect ("TEST", "", "");
global $conn_id;
class odbc_obj {
var $result;
function set_rs ($res) {
$this->result = $res;
}
function out ($eingabe) {
$retval = odbc_result($this->result,$eingabe);
return $retval;
}
}
function ConnExecute($sql)
{
global $conn_id,$did;
$did = odbc_exec ($conn_id, $sql);
$retval = new odbc_obj;
$retval->set_rs ($did);
return $retval;
}
--- index.php ---
include("odbc.php");
$sql = "<some sql query string>";
$rs = ConnExecute($sql);
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=10790&edit=2