By: Matt Puchlerz
Date: 2006-01-24
Time: 04:25
|
Using constantsThis is a trick I just figured out today, so I apologize if this is common knowledge.
I was wondering about using constants with TBS. Searching the forum turned up adding another function and using MergeBlock and so forth to gain access to constants. (http://www.tinybutstrong.com/forum.php?msg_id=2114) But I realized there was a much much easier way. PHP has a built-in function called get_defined_constants() that returns an assoc array of (surprise!) all defined constants. It is available in PHP4.1 and later. If you use this function to create a global array, or property if you're using the object-oriented features of TBS, you can access these just like you would any other variable. For example...
There you have it. Easy to use constants with no extra constant parsing function, no MergeBlock, no fuss, no mess. Again, if this was an obvious technique, I apologize. Figured it deserved a place on the forum. - Matt |
|
By: Skrol29
Date: 2006-01-24
Time: 14:49
|
Re: Using constantsSmart !
I transfert your post into the Tips & Tricks forum |