Static Functions in php

Static methods in PHP 5

In PHP 5, we can also define a method as static, which means that it is called on a class and not on an object. A static method has no access to any object properties and is created and accessed as in example :


class User {
	static function pwd_string() {
		echo "Please enter your password";

User::pwd_string (); // Calling pwd_string (without object creation) 


Note how the class itself is called, along with the static method, using a double colon (also known as the scope resolution operator) and not ->. Static functions are useful for performing actions relating to the class itself, but not to specific instances of the class.


Please enter your password

You may also like...