How to use static keyword in PHP

General discussions related to php

Moderators: macek, egami, gesf

phpkiller
New php-forum User
New php-forum User
Posts: 31
Joined: Thu Jun 28, 2012 2:11 pm

How to use static keyword in PHP

Postby phpkiller » Tue Dec 18, 2012 12:52 am

< ?
class myClassName
{
static private $mystaticvariable; //Defining Static Variable

function __construct($value)
{
if($value != "")
{
myClassName::$mystaticvariable = $value; //Accessing Static Variable
}
$this->getStaticData();
}

public function getStaticData()
{
echo myClassName::$mystaticvariable; //Accessing Static Variable
}
}

$a = new myClassName("12");
$a = new myClassName("23");
$a = new myClassName("");
?>

Return to “PHP General”

Who is online

Users browsing this forum: phprabit and 1 guest

cron