Blogger Information
Blog 250
fans 3
comment 0
visits 322900
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
OOP 面向对象 static静态修饰符
梁凯达的博客
Original
1099 people have browsed it

实例

<?php
	
	//static 
	//1. 静态的内容可以修饰成员属性和成员方法  不能修饰类
	//2.静态的成员需要使用范围操作符访问::  A::$name 如果访问的是静态属性 一定要加上$符  A::say()
	//self 代表是是类  表示的自己
	//3. 静态的成员方法里面不能出现非静态内容($this 和非静态的成员)
	//4.静态方法里面只能使用静态属性
	


	//不能修饰
	//static class A{

	//}
	class A{
		static public $name = '清早起来打开窗 满满的正能量';
		public $age = 18;
		static public function say(){
			//echo '我听说腰子姐要上春晚了!!不是央视的';
			//静态方法里面不能出现分静态内容
			//echo $this->age;
			//echo A::$age;
			//echo A::$name;
			//self 代表的是类 表示的是自己
			echo self::$name;
		}
	}
	//$a = new A;
	//echo $a->name;
	
	//访问静态的属性 一定要加上$
	
	echo  A::$name;

	//调用静态方法
	A::say();

运行实例 »

点击 "运行实例" 按钮查看在线实例

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post