1.

What Is Static Keyword In Php?

Answer»
  • If we declare a METHOD or Class Property as static, then we can access that without use of instantiation of the class.
  • Static Method are faster than NORMAL method.
  • $this is not available within Static Method.
  • Static properties cannot be accessed through the object(i.e arrow operator)
  • Calling non-static METHODS with Scope RESOLUTION operator, generates an E_STRICT level warning.
  • Static properties may only be initialized USING a literal or constant value.
  • Static properties/Normal properties Can't be initialized using expressions value.

class StaticClass

{

public static $staticValue = 'foo';

 

public function staticValue() {

return self::$my_static;

}

}

echo StaticClass::$staticValue;

class StaticClass

{

public static $staticValue = 'foo';

 

public function staticValue() {

return self::$my_static;

}

}

echo StaticClass::$staticValue;



Discussion

No Comment Found