Home > Backend Development > PHP Tutorial > php 类 疑问

php 类 疑问

WBOY
Release: 2016-06-23 14:05:56
Original
979 people have browsed it

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


回复讨论(解决方案)

那在connect.php 中 $db 可用吗

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

文件是否include成功了?

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

connect.php 贴出来就看看

文件connect.php 实例化数据库:$db=new Db()  这个样例:

class connect()
{
    public $db;

    构造函数: $this->db=new Db()

}


class A{ 

使用:$aa = new  connect;

$aa ->db->....

  }

我觉得版主说的有道理 有可能重载了

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template