Blogger Information
Blog 250
fans 3
comment 0
visits 321733
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
OOP 对象中的伪变量$this
梁凯达的博客
Original
1104 people have browsed it

实例

<?php

	//定义一个小鸭类
	
	class Duck{
		public $name = '丑小鸭';
		public $age = '2个月';
		public $sex = '母';

		public function say(){
				/*
				
					function 后悔(){
						抽[自己]一个嘴巴
					}
				 */ 
			//var_dump($this);
			//$this 代表是对象  表示是自己
			echo '我叫:'.$this->name.'<br/>';
		}
	}

	//实例化对象
	$cxy = new Duck;
	$cxy->say();

	echo '<hr/>';
	$qq = new Duck;
	$qq->name ='深圳第一鸭王';
	$qq->say();

	echo  '<hr/>';
	$wr = new Duck;
	$wr->name ='广州第一鸭头';
	$wr->say();

	//只能在对象的方法里面使用
	//echo $this->name;

运行实例 »

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

 

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