如何使用带有'类常量的defined()方法'在PHP中定义为特定类?

时间:2015-06-05 03:10:58

标签: php class oop defined class-constants

以下是类代码的小代码片段:

<?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 个答案:

答案 0 :(得分:2)

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

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