In php using :: we can access a non static member function , but how can i access the member variable same using scope resolution operator ?
<?php
class abc
{
public static $data="i am static membervaribale".'</br>';
public $data1="i am not a static membervaribale".'</br>';
public function a()
{
echo "I am a non static method".'</br>';
}
public function getsize()
{
return self::$data;
}
}
echo abc::$data;
//echo abc::$data1;//showing error;
echo abc::a();
echo abc::getsize();
$obj=new abc;
echo $obj->data1;
?>
the access to not static member the class is based on $this. So you should use
$this->data1;
and for a new object of the class abc()
$myObejct = new abc();
$myObject->data1;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.