constmgr
1. description
2. example
3. author
4. credits
5. conclusion
1. description
=================================
constmgr is used to define constants and update their values on the fly.
1) make an instance of constmgr class
2) you MUST set/define constants using the constmgr class
3) accessing the value:
${SOME_CONSTANT}
or
$obj->get( "DRAGON" );
Note:
possible common mistakes
1) accessing directly: SOME_CONSTANT after its definition with constmgr class
e.g.:
$obj =& new constmgr();
// this method call won't update the value
$obj->set( "DRAGON", "DRAGON value" );
// WRONG! way
print "defined const:" . DRAGON . "\n";
// RIGHT! ways
// 1)
print "New value:" . ${DRAGON} . "\n"; // always use this style to access the new value
// 2)
print "Get: " . $obj->get( "DRAGON" ). "\n\n";
2) defining SOME_CONSTANT before defining it with constmgr class
e.g.:
define( "DRAGON", "first DRAGON value" );
$obj =& new constmgr();
// this method call won't update the value
$obj->set( "DRAGON", "DRAGON value" );
2. example
=================================
please check the example file in the same directory
3. author
=================================
Svetoslav Marinov <svetoslav.marinov@gmail.com>
He is studying computer sciences and technologies in technical university of Sofia, Bulgaria.
He has also a master degree in Electrical Engineering department in same university.
At this moment he works for a big hosting company. In his free time
he works on http://devquickref.com - Developers' quick reference site which contains
( in future ) useful code snippets,tips,tricks etc.
bugs,comments,improvements are always welcome.
4. credits
=================================
I was inspired to made this class when checking php's online docs at
http://www.php.net/manual/en/language.variables.variable.php
************************** example **************************
rafael at fuchs inf br
21-Mar-2005 11:08
You can use constants in variable variables, like I show below. This works fine:
<?
define("TEST","Fuchs");
$Fuchs = "Test";
echo TEST . "<BR>";
echo ${TEST};
?>
output:
Fuchs
Test
************************** example **************************
5. conclusion
=================================
when accessing constants with style like this one ${DRAGON} may be a little bit
annoying for you but it is a matter of choice.
if you find this package useful use it.
all the best!
Svetoslav
|