zoukankan      html  css  js  c++  java
  • 20170929php

    这是之前学习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;

    ?>

  • 相关阅读:
    C语言运算符优先级和口诀
    跨域问题的解决方案 php
    浅谈跨域攻击及预防
    浅析Websocket--PHP
    linux下的删除目录和文件的方法
    python魔法方法
    双指针
    python常用模块
    python三大器
    对闭包的误区
  • 原文地址:https://www.cnblogs.com/Megau/p/7609735.html
Copyright © 2011-2022 走看看