如何使用定义为 PHP 中特定 class 的 'Class Constants' 的 defined() 方法?

How to use defined() method with 'Class Constants' that are defined into a specific class in PHP?

以下是 class 代码的一小段代码:

<?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";
    }
  } 
}    
?>

我已经在我有疑问的代码中添加了注释。请告诉我根据编码标准对 class 常量使用 defined() 函数的正确方法吗?

谢谢。

您可以使用 self::static:: 来解析 defined() 中的 class 常数:

if (defined('self::PW_DEBUG') && self::PW_DEBUG) {
}