Reputation: 8334
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
Upvotes: 1
Views: 81
Reputation: 57650
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";
}
Upvotes: 2