we all know how a ststic keyword works in an object-oriented Programming Language like JAVA….we can also implement same concept in PHP too…

Let’s see how it works….


/*create a class of your choice…*/

class myclass


/* declare a static variable $name for example…*/

public static $name = “KRISHNA MANOJ”;

public static getName()


return self::$name;

/**self:: is to be used to indicate that $name  belongs to this class only…else we will not get any printed Output…**/



/* execute the function with object….*/

$obj = new myclass();

echo  $obj->getName();//works well as we are printing name from a function

/* with the classname itself….*/

echo myclass::getName();



Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s