主页
PHP
PHP protected 关键字
tryphp_keyword_protected
运行 ❯
×
更改方向
保存代码
更改主题
<?php class MyClass { protected $number = 0; } class AnotherClass extends MyClass { public function add1() { $this->number++; } public function getNumber() { return $this->number; } } $obj = new AnotherClass(); $obj->add1(); echo "The number is " . $obj->getNumber(); ?>