php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10790 Cannot redeclare function/class from included file
Submitted: 2001-05-10 10:57 UTC Modified: 2001-07-02 12:15 UTC
From: christian dot huff at silur dot de Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.5 OS: Win2k,IIS5
Private report: No CVE-ID: None
 [2001-05-10 10:57 UTC] christian dot huff at silur dot 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-Projekte\Test\odbc.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);

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-10 11:50 UTC] sniper@php.net
What if you use include_once() instead of include() ?
Does it make any difference?

--Jani

 [2001-05-10 12:25 UTC] christian dot huff at silur dot de
Using include_once() does not make any difference.
 [2001-05-13 17:36 UTC] christian dot huff at silur dot de
Shall I post my configuration files? Just in case it might help with the reconstruction of that error...
 [2001-06-16 13:01 UTC] sniper@php.net
The script of yours is buggy.
this is not the right forum to ask support questions.

 [2001-07-02 12:15 UTC] christian dot huff at silur dot de
Then why does it work every second time??
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 00:01:27 2024 UTC