这是之前学习PHP类使用的代码
<?php
class animal{ var $name="1"; var $sex="2"; public static $age; function setName($name1){ $this->name = $name1; }function setSex($sex){
$this->sex = $sex;//sex为对象属性 $sex为局部变量 }public static function setAge($age){
animal::$age = $age; }function getSex($sex){
return $this->sex; }}
$tom = new animal ; //类的静态方法,属性,调用$tom = new animal();$tom->name = "json";//print $tom->name;$tom->setName("TomSet");
$sex = utf8_encode("男");$tom->setSex($sex);//名字转码后储存//print $tom->name; //$tom ->name = "NewTom";//print $tom->name;animal::$age = 22;//静态变量赋值
//print animal::$age;//静态变量取用animal ::setAge(10);//print animal::$age;//静态变量取用
$tomJson = json_encode ($tom);
var_dump ($tomJson);$tom2 = json_decode ($tomJson,true);3.6var_dump ($tom2);$newsex = $tom2->getSex();$newsex = utf8_decode($newsex);print $newsex;?>