文件Db.class.php 定义数据库操作类Db
文件connect.php 实例化数据库:$db=new Db()
文件function.class.php定义其他类
现有 class A{
              function test(){
                     include('connect.php');
                     $db为什么在这里不能使用?
              }
}phpincludeclass

解决方案 »

  1.   

    那在connect.php 中 $db 可用吗
      

  2.   

    1、确定 connect.php 文件中的 $db是否可用;
    2、确认connect.php的文件路径没有引用错误
      

  3.   

    还有一种可能:Db.class.php 被重复加载了
      

  4.   

    文件connect.php 实例化数据库:$db=new Db()  这个样例:class connect()
    {
        public $db;    构造函数: $this->db=new Db()}
    class A{ 使用:$aa = new  connect;$aa ->db->....  }