php代码序列化后的基本格式如下
O:<length>:"<class name>":<n>:{
<field type 1>:<field length 1>:"<field name 1>";<field value type 1>:<field value 1>;
...
<field type n>:<field length n>:"<field name n>";<field value type n>:<field value n>;}
O:表示序列化的事对象
< length>:表示序列化的类名称长度
< class name>:表示序列化的类的名称
< n >:表示被序列化的对象的属性个数
{…………}:属性列表
< field type >:属性类型
< field length >:属性名长度
< field name >:属性名
< field value type >:属性值类型
< field value >:属性值
其中,protected类型的属性,其名称默认" *+属性名 ",private 类型的属性,名称默认“ 类名+属性名 ”。
另外,它们的< field length >与目测长度不符,实际上,它们中间有两个不可见字符%00
"Testc" = “%00Test%00c”
"*c" = “%00*%00c”
例:
<?php
class Test{
public $a;
protected $b;
private $c;
var $d;
static $e;
function __construct(){
$this->a=$this->b=$this->c=$this->d=$this->e=1;
}
}
$t=new Test();
echo(serialize($t));
>
/* O:4:"Test":5:{s:1:"a";i:1;s:4:"*b";i:1;s:7:"Testc";i:1;s:1:"d";i:1;s:1:"e";i:1;} */
咱只是一个贼菜的鶸,也没看过相关的书,以上内容是总结自下面两个地方的,如有错误,希望大佬们能够指出。
参考:
https://blog.youkuaiyun.com/weixin_45689999/article/details/104608039
https://www.bilibili.com/video/BV1Z54y1U7up