可以在PHP框架的模型文件中定义常量吗?


Can the constants be defined inside a model file of a framework in PHP?

我使用PHPFox框架。我必须定义两个常量,它们将仅由模型类文件中的两个函数使用。所以我可以在这个模型类文件的开始定义常量,或者它会导致任何问题,或者它违反编码标准?

请在这方面帮助我。

下面是这个模型类文件中的一个方法。

我想写以下代码:

<?php
/**
 * [PHPFOX_HEADER]
 */
/*header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');*/
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
     */ 
    public function __construct()
    {   
        $this->_sTable = Phpfox::getT('notification');
    }
    public function add($sType, $iItemId, $iOwnerUserId, $iSenderUserId = null)
    {
        if ($iOwnerUserId == Phpfox::getUserId()&&$iSenderUserId==null)
        {
            return true;
        }
        if ($sPlugin = Phpfox_Plugin::get('notification.service_process_add'))
        {
            eval($sPlugin);
        }       
        if (isset($bDoNotInsert) || defined('SKIP_NOTIFICATION'))
        {
            return true;
        }
        $aInsert = array(
            'type_id' => $sType,
            'item_id' => $iItemId,
            'user_id' => $iOwnerUserId, 
            'owner_user_id' => ($iSenderUserId === null ? Phpfox::getUserId() : $iSenderUserId),
            'time_stamp' => PHPFOX_TIME     
        );  
        $this->database()->insert($this->_sTable, $aInsert);    
        return true;
    }
}
?>  

我想定义以下两个常量:

define('PW_AUTH', '8s4QpeUyLX9BodAy');
define('PW_APPLICATION', 'R8T89-29690');

将它们设置为类中的常量。

来自PHP手册:

<?php
class MyClass
{
    const CONSTANT = 'constant value';
    function showConstant() {
        echo  self::CONSTANT . "'n";
    }
}