php之static静态属性与静态方法实例分析,static实例分析_PHP教程

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

php之static静态属性与静态方法实例分析,static实例分析

本文实例讲述了php之static静态属性与静态方法。分享给大家供大家参考。具体如下:

<&#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

运行结果如下:

地方
政府
政府
I am 星星

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1040811.htmlTechArticlephp之static静态属性与静态方法实例分析,static实例分析 本文实例讲述了php之static静态属性与静态方法。分享给大家供大家参考。具体如下:...
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!