How to use static keyword in PHP

General discussions related to php

Moderators: egami, macek, gesf

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

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("");
?>

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest