当前位置:网站首页>serialization and deserialization
serialization and deserialization
2022-07-25 23:08:00 【April Gypsophila】
The definition of serialization and deserialization :
serializeIt is the process of converting an object into a byte sequence of a string for storage
"O:6:"People":3:{s:4:"name";s:5:"error";s:3:"age";s:2:"20";s:3:"sex";s:1:"M";}"
It can be seen that , After serialization, the output result is a string of characters .
O Express object, An object
6 "People" Indicates that the length of the object name is 6, be known as "People"
3 Express 3 Attributes
s by "string" type
4 For attributes name The length of
7 For attribute value error The length of
And so on , The properties of a class are ;N; ending ,;} End a string of serialized characters .
serializeThe most importanteffect: When passing and saving objects . Ensure the integrity and transitivity of the object . Object into an ordered byte stream , To transfer over the network or save in a local file .DeserializationIs the string ( example ) Process of converting to object
DeserializationThe most important role of : According to the object state and description information saved in the byte stream , Rebuild objects by deserializing .
PHP Principle of deserialization
The serialized string entered by the user was not detected , This will allow the attacker to control the deserialization process , This leads to code execution ,SQL Inject , Directory traversal and other uncontrollable consequences . Some magic methods are automatically triggered during deserialization . When deserializing, it is possible to trigger some magic methods in the object .
PHP The key functions of serialization and deserialization :
serialize(): Convert an object to characters
unserialize(): Restore characters to an object
The technology used in deserialization can be distinguished between class and non class by checking whether there is class, There is a class , Where there are classes, there will be magic methods
PHP Center the two underscores __ The first method is called magic method (Magic methods), These methods are in PHP It plays a very important role in .
PHP Specific cases of magic methods can be referred to PHP manual —PHP Magic method
Specific methods and cases
Detailed explanation of sixteen magic methods :
https://segmentfault.com/a/1190000007250604
- _ _construct(): Class constructor
Precautions for declaring constructors in classes
Only one constructor can be declared in the same class , as a result of ,PHP Constructor overloading is not supported
- _ _destruct(): Destructor of class
Generally speaking , The method of deconstruction is in PHP Is not very commonly used , It is an optional part of the genus , It is usually used to clean up objects before they are destroyed .
- _ _call(): Called when an invocable method is invoked in an object
- _ _callStatic(): Call in an static way when an invocable method is called
- _ _get(): Call when you get a member variable of a class
stay PHP In object oriented programming , The member attribute of a class is defined as private after , If we try to call it outside, it will appear “ A private property is not accessible ” Error of . So in order to solve this problem , We can use _ _get().
_ _get The role of , While the program is running , Through it, you can get the value of private members outside the object
- _ _set(): Called when setting a member variable of a class
- _ _isset(): When an inaccessible property is called isset() or empty() Called when the
- _ _unset(): When called on an inaccessible property unset() When called
- _ _sleep(): perform serialize() when , This function will be called first
- _ _wakeup(): perform unserialize when , This function will be called first
- _ _toString(): The response method when a class is treated as a string
- _ _invoke(): The response method when an object is called by calling a function
- _ _set_state(): call var_export() When exporting a class , This static method will be called
- _ _clone(): Called when the object copy is complete
- _ _dutoload(): Trying to load an undefined class
- _ _debugInfo: Print the required debug information
Range training
边栏推荐
猜你喜欢

Hcie is finally in hand, and the road begins
![[文献阅读] - HRL -[HRL with Universal Policies for Multi-Step Robotic Manipulation]](/img/34/06d5ba3af4e6e775a335324c020161.png)
[文献阅读] - HRL -[HRL with Universal Policies for Multi-Step Robotic Manipulation]

互联网协议之 IPFS

5 ROS仿真建模(3- rviz+gazebo+控制仿真机器人)

通用分页功能

第二周学习:卷积神经网络

Network Security Learning (11) scanning and blasting

Experience of machine learning with Google Lab

AI首席架构师12-AICA-工业生产过程优化场景下产业落地解析

Stack and stack class
随机推荐
Simulink learning notes (III) - Simulink automatic code generation (II) "suggestions collection"
2020-09-17
Learning notes of technical art hundred people plan (1) -- basic rendering pipeline
What are the differences between FileInputStream and bufferedinputstream?
Stack and stack class
校验码生成
js正则表达式匹配ip地址(ip地址正则表达式验证)
Network Security Learning (16)
QT operation to solve large amount of duplicate data
firewall 命令简单操作
access-list vs ip access-list
Ma Tiji Wanmin hall Chef
Network Security Learning (11) scanning and blasting
驱动板网线直连电脑共享网络配置
About using NPM command under the terminal, the installation error problem is solved (my own experience)
Redis expiration key deletion strategy [easy to understand]
MathType安装和解决不能Crtl+V的问题
AI首席架构师12-AICA-工业生产过程优化场景下产业落地解析
Node.js operation database
Mongodb的特点、与MySQL的差别、以及应用场景