문제 설명
PHP의 특정 클래스에 정의된 '클래스 상수'와 함께 defined() 메서드를 사용하는 방법은 무엇입니까? (How to use defined() method with 'Class Constants' that are defined into a specific class in PHP?)
다음은 클래스 코드의 작은 코드입니다.
<?php
/**
* [PHPFOX_HEADER]
*/
defined('PHPFOX') or exit('NO DICE!');
/**
*
*
* @copyright [PHPFOX_COPYRIGHT]
* @author Raymond Benc
* @package Phpfox_Service
* @version $Id: service.class.php 67 2009‑01‑20 11:32:45Z Raymond_Benc $
*/
class Notification_Service_Process extends Phpfox_Service
{
/**
* Class constructor
*/
const PW_AUTH = 'xxxxxxxx';
const PW_APPLICATION = 'XXXX‑XXX';
const PW_DEBUG = true;
public function __construct()
{
$this‑>_sTable = Phpfox::getT('notification');
}
public function pwCall() {
if (defined('PW_DEBUG') && self::PW_DEBUG) { // Is this a right way to use defined() method for class constants?
print "[PW] request: Request come\n";
print "[PW] response: Response sent\n";
}
}
}
?>
내 코드에 의심스러운 부분에 주석을 달았습니다. 코딩 표준에 따라 클래스 상수에 대해 defined() 함수를 사용하는 것이 올바른 방법인지 알려주세요.
감사합니다.
참조 솔루션
방법 1:
You could use self::
or static::
to resolve the class constant in defined()
:
if (defined('self::PW_DEBUG') && self::PW_DEBUG) {
}