HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
PHP Keywords : Create and use static properties and methods
The static
keyword is used to declare properties and methods of a class as static. Static
properties and methods can be used without creating an instance of the class.
The static
keyword is also used to declare variables in a function which keep their value
after the function has ended.
Read more about static methods in our PHP OOP - Static Methods Tutorial.
Read more about static properties in our PHP OOP - Static Properties Tutorial.
Use a static variable in a function:
<?php
function add1() {
static $number = 0;
$number++;
return $number;
}
echo add1();
echo "<br>";
echo add1();
echo "<br>";
echo
add1();
?>
❮ PHP Keywords