1

I am creating a constant mirror of my Database so i don't have problems with typo's anymore.

what i was hoping to achieve is to brouwse trough it in a folder like structure. like:

echo Db::categorie::id;  // should return Cat_ID

is this possible, or something simmilar? now it gives errors because it is not possible. below the code:

class Db // database
{
    /*@var $categorie DbCatergorie*/
    const categorie = DbCatergorie;
}

class DbCatergorie // table in database
{
    Const id = "Cat_ID";
    Const name = "Cat_Name";
    Const imgId = "Cat_Img_ID";
    Const volgorde = "Cat_Volgorde";
}

thx Matthy

2
  • 4
    class constants cannot be variables, properties, the results of a mathematical operation, or a function call... or classes. You'd be better off defining a static property. Commented Feb 5, 2012 at 22:47
  • Use static property and set in construct. Commented Feb 6, 2012 at 5:34

1 Answer 1

2

This is not possible.
Class constants must be a constant. Not even constant expressions are supported.

From manual

The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call.

// Wrong!
class C{
    const c = 54*34;
}

If you are worried about typo, I suggest this,

class Db // database
{
    Const CAT_ID = "Cat_ID";
    Const CAT_NAME = "Cat_Name";
    Const CAT_IMG_ID = "Cat_Img_ID";
    Const CAT_VOLGORDE = "Cat_Volgorde";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.