PHP static attributes and static method instance analysis, static instance analysis_PHP tutorial

WBOY
Release: 2016-07-13 09:45:34
Original
835 people have browsed it

Analysis of static static attributes and static methods in PHP, static instance analysis

This article explains the static attributes and static methods in PHP with examples. Share it with everyone for your reference. The details are as follows:

<&#63;php
/*
 * static
 */
 /*静态:属于类而不属于单个对象 (全局的,所有对象共享的)
 *静态属性:类的方法内调用静态属性时,不要使用$this->方式,而要使用self::的方式
 *静态方法:
 *在类没有任何对象的时候也能被调用
 *当成普通方法来用也没问题的
 *在静态方法中不能调用普通方法
 * 
 * */
 class xin {
  static private $name;
  public function setname($namec) {
    self::$name = $namec;
  }
  public function getname() {
    return self::$name;
  }
  static public function name($namecc) {
    echo "I am $namecc";
  }
 }
 $xind = new xin();
 $xind->setname("地方 <br/>");
 echo $xind->getname();
 $oldd = new xin();
 $oldd->setname("政府 <br/>");
 echo $oldd->getname();
 echo $xind->getname();
 echo xin::name("星星");
 echo "<br/>";
&#63;>

Copy after login

The running results are as follows:

Place
Government
Government
I am stars

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1040811.htmlTechArticlePHP’s static static attributes and static methods example analysis, static example analysis This article explains the static static attributes and static methods of PHP static method. Share it with everyone for your reference. The details are as follows:...
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