Skip to Content
PHPCODE
Static Members in php
oops code / August 11, 2018
<?php
class abc
{
public static $data=’test data’;
public static function xyz()
{
echo ‘xyz function’;
}
}abc::xyz();
?>2.programming

<?php
class House {
public static $size=2500;
public static function getSize()
{
return self::$size;
}
public static function setSize($size)
{
self::$size=$size;
}
}
House::setSize(1200);
echo House::getSize();
?>

3.Object Count++

<?php
class abc {
public static $objectCount=0;
public static function getCount()
{
return self::$objectCount;
}
public function __construct()
{
self::$objectCount++;
}
}
$a=new abc();
$b=new abc();
$c=new abc();
$d=new abc();
echo  abc::getCount();
?>

PHPCODE © 2024