Using static methods in objects PHP - is it advantage?

Posted by RePRO on Programmers See other posts from Programmers or by RePRO
Published on 2012-03-21T15:14:22Z Indexed on 2012/03/21 17:38 UTC
Read the original article Hit count: 193

Filed under:

I was reading some articles and discussions on the use of static methods on objects and it struck me how much the views differ.

Someone say that using static methods is an advantage. Someone says that use is a big mistake.

I wonder how is it? My question is when to use static methods and when not?

I would like to hear answers from experts in this field (PHP OOP). This is because I know how it really is.

The following code should be analogous. Just call the static method is simpler (my opinion):

<?php    

    class A
    {
        public function write($a) {
            echo $a; 
        }
     }

     class B
     {
        public static function write($a) {
            echo $a;
        }
     }

     $a = new A;
     $a->write(5); // 5

     B::write(5);  // 5
?>

Thank you.

© Programmers or respective owner

Related posts about php