Jump to content

[SOLVED] Declaring array constant


simpli

Recommended Posts

Hi,

I want to declare an array constant to use as JSON header.

I do the following but I get an error.

class Model_DbTable_Tree extends Zend_Db_Table_Abstract 
{ 
    protected $_name   = 'tree';
    protected $_primary = 'node_id';
const $_JSON_HEADER = array("label" => "node_name", "identifier" => "node_id");

 

but I get an error message:

Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING in /Library/WebServer/Documents/budgetobjects/application/models/DbTable/Tree.php on line 8

 

I'm using Zend 1.8. Can anyone tell me how to declare that constant properly?

Thanks,

JR

Link to comment
https://forums.phpfreaks.com/topic/162223-solved-declaring-array-constant/
Share on other sites

you could define and initialize an static array variable:

 

ie

class  Model_DbTable_Tree extends Zend_Db_Table_Abstract 
{
    protected $_name   = 'tree';
    protected $_primary = 'node_id';
    public static $_JSON_HEADER = array("label" => "node_name", "identifier" => "node_id");
}

  • 2 weeks later...

define the constant as a serialized array, then unserialize when you use it:

define('MyConst','a:3:{i:0;s:16:"This is an array";i:1;s:20:"but it is serialized";i:2;s:44:"so the serialized string is a valid constant";}');

print_r(unserialize(MyConst));

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.