If it's just a namespaced function, MyClass::foo() is probably fine.
BTW, unless you're using PHP 4,
the pass-by-reference stuff is unnecessary.  PHP 5 always passes
objects by reference.

-Matt

On Sun, Jun 21, 2009 at 9:50 AM, howard chen <howac...@gmail.com> wrote:

> Hello,
>
> It is not a 100% zfw question, but as I am coding under zfw, so I want
> if my OO coding is consistent with the zfw.
>
>
> Example:
>
> I have a Class - MyClass, it is a global functional object, has the
> function foo() I need to call in several php files for a single HTTP
> request.
>
> ============
> class MyClass{
>
>    function MyClass () {
>        $this->init();
>    }
>
>    function &getInstance {
>        static $instance;
>
>        if (!isset($instance)) {
>            $instance = new MyClass();
>        }
>
>        return $instance;
>    }
>
>    function init() {
>        // Some heavy init codes...
>    }
>
>    function foo() {
>        // core function
>    }
>
> }
> ============
>
>
> Which one you prefer:
>
>
> 1. Call as global class:
>
>
> $data = MyCalss::foo();  // put init() in bootstrap
>
>
> 2. Call as singleton
>
> $myClass =& MyClass::getInstance();
> $myClass->foo();
>
> 3. Call as new object
>
> $myClass = new MyClass();
> $myClass->foo();
>
>
>
> which method you prefer?
>
>
> Thanks.
>

Reply via email to