Page 1 of 1

PHP coding standard: using self::method() vs $this->method()

Posted: Tue Mar 02, 2010 6:17 pm
by jeff00seattle
If a class method() is not static, and even though it works calling it with self::method(), I want to know if this is totally uncool and does not meet to PHP coding standards?

To meet to PHP coding standards (PEAR), then must I restrict myself to:
  • Use only $this-> when referring to non-static class methods and member variables
  • Use only self:: when referring to static methods and constants
Advise?

Thanks

Jeff in Seattle

Re: PHP coding standard: using self::method() vs $this->method()

Posted: Tue Mar 02, 2010 6:20 pm
by josh
I think it will throw an E_STRICT. Its not "cool" to use static methods unless there is no "state"

$result = Math:add( 5, 5 ); // legit place to use "static", there is no state
$cart->changeQuantity(5); // if there is "state", a conceptual "object", static usage leads to "global state"

http://www.youtube.com/watch?v=-FRm3VPhseI