PHP Static Methods and Variables:
In this tutorial we will study when we should use static methods and variables.
Static keyword is used to make only one copy of the variable for the class. All objects of that class will access one copy of that attribute. Static data are used when some data has to share within the all objects of that class.
If we declare a method as static then we can access the method using class, without instantiating any object.
Example of PHP Static Variables & Methods :
<?php
class One{ private static $var=0; function __construct(){ echo "Inside constructor"; self::$var++; print self::$var;} static function disp(){ print self::$var;}}One::disp();
?>
Output:
0
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.