Analysis of static static attributes and static methods in php_php skills

WBOY
Release: 2016-05-16 20:09:14
Original
2135 people have browsed it

The examples in this article describe the static attributes and static methods of PHP. 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.

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