0
PHP에서 enum의 부족을 대신하여 인터페이스를 사용하려하지만 원하는 방식대로 작동하지 않는 것 같습니다. 출력이 abrand
대신 A Brand
입니다 왜클래스 내에서 enum 스타일 값을 가져 오는 중입니까?
interface Brands
{
const abrand = "A Brand";
const anotherbrand = "Another Brand";
}
class Product
{
private $brand;
function __construct() {
}
public function getBrand() {
return Brands::$this->brand;
}
public function setBrand($value) {
$this->brand = $value;
}
}
$product = new Product();
$product->setBrand("aproduct");
echo $product->getBrand();
누군가가 설명 할 수 : 여기
코드인가?
왜 사용합니까'브랜드 : $ this-> brand' 대신 간단한 '브랜드의 :: abrand'? 이'Brands :: $ this-> brand'와 같은 구조로 PHP의 역 동성을 계속 사용하면서 enum을 모방하고 싶다면 이상합니다. 어쨌든,'Brands ::'접두사는 모두 무시되며'$ this-> brand'의 값만 반환합니다. –
오,이 사람이 내 생각에 ... 그게 바보 같았 어 (대답 참조) – Microsis
하하, 문제 없습니다. 나는 좋은 고무 오리 (http://en.wikipedia.org/wiki/Rubber_duck_debugging을 이해하지 못하는 사람들에게)의 기록을 가지고있다. –