1

以下は、クラス コードの小さなコード スニペットです。

<?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() 関数を使用する正しい方法を教えてください。

ありがとう。

4

1 に答える 1

2

self::またはを使用static::してクラス定数を解決できdefined()ます。

if (defined('self::PW_DEBUG') && self::PW_DEBUG) {
}
于 2015-06-05T03:26:50.867 に答える