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
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");
}

Link to comment
Share on other sites

  • 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));

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.