아니요, 클래스 생성자에서 상수를 정의할 수 없습니다. 클래스 수준에서 상수를 사용할 수 있습니다.
다음 클래스가 있다고 가정해 보겠습니다. −
class ConstantDemo
{ } 클래스에서 상수 정의 -
class ConstantDemo {
const LANGUAGE_NAME="PHP";
} 예시
<!DOCTYPE html>
<html>
<body>
<?php
class ConstantDemo {
const LANGUAGE_NAME="PHP";
}
echo "The language Name is=",ConstantDemo::LANGUAGE_NAME;
?>
</body>
</html> 출력
The language Name is=PHP