-1
나는 oop을 배우고 있습니다. 나는 덮개를 덮고 그 뒤에있는 생각을 이해하려고 노력합니다. 코드가있어서 이해를 위해 static을 사용하고 싶습니다. 속성 선언 : protected static $formula
. protected static $formula
에 self :: $formula = $this->width * $this->height;
으로 전화합니다. 디버거에서 코드를 실행할 때 $formula = null
이 있습니다. `$ formula '는 = 10000이어야합니다. 이유를 모르겠습니다. 도움 주셔서 감사합니다.보호 된 정적으로 oop에서 사용하고 싶습니다.
<?php
Class Rectangle {
//Declare the attributes:
public $width = 0;
public $height = 0;
protected static $formula = 0;
//Method to set the dimensions.
Function set_size($w = 0, $h = 0) {
$this->width = $w;
$this->height = $h;
self :: $formula = $this->width * $this->height;
}
//Method to calculate and return the area.
function get_area() {
$this->set_size(100,100);
return ($formula);
}
}
$rect = new Rectangle();
echo $rect->get_area();
>