小编J2D*_*D8T的帖子

PHP:类与实例变量

我知道 Java 和 C# 等编程语言中的类变量和实例变量存在差异,所以我想知道 PHP 是否相同。

所以我知道类变量在该类的所有实例之间共享,而实例变量仅与该类的特定实例相关。

例如:

class db {
  private $host;   <--
  private $user;   <-- These will be treated as instance variables
  private $pass;   <-- as they are set by the class constructor
  private $dbname; <--

  private $connected = false; <-- Will this be treated as a class 
                                  variable? Shared among all the 
                                  instance of the db class?

  public function __construct($host, $user, $pass, $dbname) {
    $this->host = $host;
    $this->user = $user;
    $this->pass = $pass;
    $this->dbname = $dbname; …
Run Code Online (Sandbox Code Playgroud)

php oop

2
推荐指数
1
解决办法
5581
查看次数

标签 统计

oop ×1

php ×1