php面向对象

转:http://www.cnblogs.com/52php/p/5658145.html

http://php.net/manual/zh/language.oop5.php

<?php

class myclass{
public $username;
private $sex;
function __construct(){
$this->username="victor";
$this->sex="男";
echo "class start<br>";
}
function __destruct(){
echo "<br>class end";
}

function __call($func_name,$func_param){
echo $func_name." is not exist<br>";
print_r($func_param);
echo "<br>";
}

function read_var(){
return $this->username;
}

function test($name,$age){
return $name."=".$age;
}

function __get($param_name){
echo $param_name ." is not exist";
if(isset($this->$param_name))
{
return($this->$param_name);
}else
{
return(NULL);
}
}

function get_sex(){
return $this->sex;
}

function __set($key,$value){
#echo "1".$key;
#echo "2".$value;
$this->$key=$value;
return $this->$key;
}

}
$test=new myclass();
$test->mytest("victor","29");
echo $test->test("yansiyu","29");
echo "<br>";
echo $test->read_var();
echo "<br>";
echo $test->username;
echo "<br>";
echo $test->age;
echo "<br>";
echo $test->get_sex();
echo "<br>";
$test->sex="女";
echo $test->sex;
echo "!";
?>

    A+
发布日期:2014年07月23日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: