This article illustrates the access method of class properties and static variables in PHP. Share to everyone for your reference, specific as follows:
<?php
/* PHP class Properties and class static variables access
* Created on 2016-7-13/class
Test
{
const constvar= ' Hello World ';
static $staticvar = ' Hello World ';
function Getstaticvar () {return
self:: $staticvar;
}
}
$obj =new Test ();
Echo Test::constvar; Output ' Hello World '
echo @test:: Staticvar;//error, Staticvar must add $ before it can be accessed, which is easy and the class constant (Per-class constant) easily confusing one of the places
Echo Test:: $staticvar; Output ' Hello world '
$str = ' Test ';
echo $STR:: $staticvar; Error, class name can not be used in this variable
//echo $str:: Constvar;//////////////////////////////////////////////////
New $str ();
echo $obj 2->getstaticvar ();
? >
Run the result: Hello World
For more information about PHP interested readers can view the site topics: "PHP object-oriented Programming Introductory Course", "PHP Mathematical Arithmetic Skills summary", "PHP Array" Operation Techniques Encyclopedia, "PHP string (String) Usage Summary", " PHP Data structure and algorithm tutorial, "PHP Programming Algorithm Summary", "PHP Regular Expression Usage Summary", and "PHP Common database Operation Skills Summary"
I hope this article will help you with the PHP program design.