> For the complete documentation index, see [llms.txt](https://bing.gitbook.io/phper/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bing.gitbook.io/phper/base/ooad/mian-xiang-dui-xiang/lei-de-bian-liang.md).

# 类的变量

```
class A
{
    protected $a;

    public function __construct()
    {
        $this->a = 1;
    }
}

class B extends A
{
    public $a;

    public function __construct()
    {
        parent::__construct();
    }

    public function getA()
    {
        return $this->a;
    }
}

$b = new B();
echo $b->getA();
```

1. 子类的属性要更加开放，父类中最好别定义public
2. 子类中要使用父类中`__construct()`变更，`__construct()`不能为空
