这是之前学习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.6
var_dump ($tom2);
$newsex = $tom2->getSex();
$newsex = utf8_decode($newsex);
print $newsex;

?>

20170929php的更多相关文章

随机推荐

  1. EF CodeFirst 数据库的操作

    生成数据库 首先需要通过Nuget安装Migration 这一步是初始化Migration操作. 首先打开程序包控制台, 工具——NuGet包管理器——程序包管理控制台 打开后,在控制台输入下面的命令 ...

  2. ArcGIS js api 手动构建FeatureLayer

    坐标系 var spatialReference = new SpatialReference(4326);1要素坐标点 var pointArr = [ new Point(116.94431351 ...

  3. table中怎么设置两行间距

    table中设置两行间距方法: css代码实现 <style> table   {   border-collapse:   separate;   border-spacing:   1 ...

  4. Python高级知识点总结

    一.可迭代对象.迭代器对象和生成器 像list, tuple等这些序列是可以使用for...in ...语句来进行遍历输出的.这是为什么呢?这就需要知道可迭代对象(Iterable).迭代器对象(It ...

  5. (转)Centos7 修改硬件时间和系统时间

    查看硬件时间 [root@localhost ~]# hwclock --show Tue 13 Jun 2017 02:11:12 AM CST -0.848845 seconds 1 2 可以看出 ...

  6. JavaEE笔记(十一)

    Spring beans使用参数占位符(JDBC配置读取示例) beans.xml配置文件 <?xml version="1.0" encoding="UTF-8& ...

  7. 对*P++的理解,再联想~~~

    前言: 最近在看一位叫朱有鹏大神的视频,讲的甚好.应此,我的感悟也因此被激发,准备针对朱老师将的内容,结合自己的理解,写一个系列的笔记博客--大家可以去www.zhulaoshi.org观看视频-- ...

  8. JS 获取每月有几周(每周五到周四算作一周)

    原文地址:https://caochangkui.github.io/data-week/ 将每周五至周四算作一周,计算每月有几周,并获取到每周的起始时间. 日期格式化 Date.prototype. ...

  9. SpringBoot中使用Quartz笔记

    Quartz可以用来做什么? Quartz是一个任务调度框架,可用来做定时任务. 吧啦吧啦......... 还是直接上代码. application.properties  配置文件. * * ? ...

  10. Spring+SpringMVC+MyBatis+easyUI整合优化篇(一)Java语言中System.out.print与Log的比较

    作者:13 GitHub:https://github.com/ZHENFENG13 版权声明:本文为原创文章,未经允许不得转载. 前言 距离上一次更新博客有一段时间了,主要是因为最近有开发任务,另外 ...