Code: Select all
class Test
{
function foo()
{
return 'foo';
}
}
echo Test::foo(); // echoes 'foo'increments the number of queries by one (for cool statistic stuff).
In PHP5, you can declare static variables in classes:
Code: Select all
class Test
{
public static $num = 0;
}Code: Select all
class Test
{
function static_num()
{
static $num = 0;
return ++$num;
}
}You could do the same for query results, too; with a function like result() storing a static $result.
The reason I'm bringing all of this up, is because it appears to me that I could use my DB class in this way, and then when my functions need to query the database, I don't have to call global $db everytime.
Is there some reason this method of database querying would be a bad practice or has some hidden problem, that you guys see and I don't?
- Monkey