0

I'm using PHPFox framework. I've to define two constants which would be used only by two functions present within that model class file. So can I define the constants at the beginning of this model class file or would it cause any issue or is it against the coding standards?

Please help me in this regard.

Following is one method from this model class file.

I want to write following code :

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

I want to define following two constants:

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

Thanks in advance.

PHPLover
  • 1
  • 51
  • 158
  • 311

1 Answers1

3

Set them as constants in the class.

From the PHP manual:

<?php
class MyClass
{
    const CONSTANT = 'constant value';

    function showConstant() {
        echo  self::CONSTANT . "\n";
    }
}
cjhill
  • 1,004
  • 2
  • 9
  • 31
  • Can't I set before the class definition? – PHPLover Jun 04 '15 at 13:34
  • Variables you `define` are for the whole application whereas class `const`ants are only used within that class (and children). Since you said *"would be used only by two functions present within that model class file"* you want to use the later, not the former. – cjhill Jun 04 '15 at 13:37