3
가능한 중복 : 다음 두 예제의 차이는 (있는 경우), 그리고 무슨 일이 무엇
Initializing Class Fields at the Field Definition or in Class Contructor
Setting variables on Constructor VS on the class definition초기화 객체 속성 - 그것을 어떻게 제대로
개체 속성을 초기화하는 적절한 방법? 이 경우 $ fields의 내용은 미리 정의 된 것이므로 런타임에 변경되지 않습니다.
예 1 :
class User
{
$fields = array('username', 'password', 'email');
function __construct()
{
}
}
예 2 :
class User {
$fields;
function __construct()
{
$this->fields = array('username', 'password', 'email');
}
}
다른 언어 ... – jondavidjohn
@jondavidjohn : 수정 됨. – hakre
@Brad 예 물론 이것은 단지 예일뿐입니다;) –