Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

How to use static keyword in PHP

General discussions related to php

Moderators: macek, egami, gesf

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("");
?>
phpkiller
New php-forum User
New php-forum User
 
Posts: 31
Joined: Thu Jun 28, 2012 2:11 pm

Return to PHP General

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.