Use of php self,$this,const,static,->_PHP Tutorial

WBOY
Release: 2016-07-21 15:43:23
Original
1059 people have browsed it

Let’s summarize today.
. When the internal method of a class accesses attributes that have been declared as const and static, use the form of self::$name. Note that the declaration format of the const attribute is const PI=3.14, not const $PI=3.14

Copy the code The code is as follows:

class clss_a {

private static $name="static class_a";

const PI=3.14;
public $value;

public static function getName ()
{
return self::$name;
}
//This way of writing is wrong, static methods cannot access non-static properties
public static function getName2()
{
return self::$value;
}
public function getPI()
{
return self::PI;
}


}

Another point to note is that if a class method is static, the properties it accesses must also be static.
. When the internal method of a class accesses attributes that are not declared const or static, use the form $this->value ='class_a';.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320765.htmlTechArticleLet’s summarize today. . When the internal method of a class accesses attributes that have been declared as const and static, use the form of self::$name. Note that the declaration format of the const attribute is const PI=3.14, and...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!