Functions with Static Variables vs. Classes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For some simple applications I use a function to collect values in a static
variable and to return them when called in a special way, just like this
(fairly senseless) example:
  function example($elem='') {
    static $store = array();
    if (!func_num_args()) return($store);
    ... do something with $elem ...
    $store[] = $elem;
  }
I would call this a singleton-micro-class, as it works like a class with
data and methods, but there is always only one of it, having only one
method.

Why do I? Because I dont need to worry about variablescope as if I would use
global variables and I dont have to initialize an object before the first
call (with the scope-problem again). I simply can call it everywhere and
everytime.

Do you have any comments to this approach?

Thomas

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux