zoukankan      html  css  js  c++  java
  • 序列化和反序列化

    <?php
    class Student{
        public $name;
        protected $sex;
        private $add;
        public function __construct($name,$sex,$add)
        {
            $this->name = $name;
            $this->sex = $sex;
            $this->add = $add;
        }
    }
    //
    $stu = new Student('tom','男','北京');
    $data = serialize($stu);        //序列化
    $fort = file_put_contents('./stu.txt',$data); //O:7:"Student":3:{s:4:"name";s:3:"tom";s:6:"*sex";s:3:"男";s:12:"Studentadd";s:6:"北京";}
    
    //反序列化必须要有类的参与,不然会显示为未知类(__PHP_Incomplete_Class)
    echo '<pre>';
    var_dump(unserialize(file_get_contents('./stu.txt'))); //发序列化 object(Student)#2 (3) { ["name"]=> string(3) "tom" ["sex":protected]=> string(3) "男" ["add":"Student":private]=> string(6) "北京" }
    

      

  • 相关阅读:
    Ext.grid.行相关
    FORM 布局
    rs.open sql,conn,1,1全接触
    arguments.callee
    Ext.window.MessageBox xtype: messagebox ; Ext.Msg Ext.MessageBox
    Ext.grid.column
    sql
    正则
    转JS
    quickFilters
  • 原文地址:https://www.cnblogs.com/shuzhixia/p/15180283.html
Copyright © 2011-2022 走看看