当前位置:网站首页>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
边栏推荐
- Firewall command simple operation
- Unity uses macros
- Panzer_ Jack's personal blog founding day
- Data filtering of MATLAB
- QT string operation
- The difference between overloading and rewriting
- Drive board network cable directly connected to computer shared network configuration
- MySQL data type
- Unity 使用宏
- uvm_hdl——DPI在UVM中的实现(四)
猜你喜欢

Mocha test

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

VisualBox启动虚拟机报错:The VM session was closed before any attempt to power it on.

Details of notification (status bar notification)

DHCP first static experiment

The third experiment OSPF
![[interface performance optimization] reasons for index failure and how to optimize SQL](/img/b9/64058c823c4497ac36bfb62a101816.jpg)
[interface performance optimization] reasons for index failure and how to optimize SQL

Longitude and latitude and its transformation with coordinate system

Extended configuration of static routing in the second experiment

Notification(状态栏通知)详解
随机推荐
Drive board network cable directly connected to computer shared network configuration
Websocket summary
QT string operation
SSH服务器CBC加密模式漏洞(CVE-2008-5161)
赋能合作伙伴,亚马逊云科技如何落地“扶上马,送一程”?
OASYS system of code audit
DHCP first static experiment
Stack simulation queue
Simulink学习笔记(三)——Simulink自动代码生成(二)「建议收藏」
每周推荐短视频:需要协同的智能设备越来越多,给物联网开发提出更大挑战?
Panzer_ Jack's personal blog founding day
Recommend short videos every week: more and more smart devices need collaboration, posing a greater challenge to the development of the Internet of things?
MathType安装和解决不能Crtl+V的问题
Similarities and differences between equals and "= ="
What has Amazon cloud technology done right to become the leader of cloud AI services for three consecutive years?
自定义mvc原理
校验码生成
Mongodb的特点、与MySQL的差别、以及应用场景
【接口性能优化】索引失效的原因以及如何进行SQL优化
Deep recursion, deep search DFS, backtracking, paper cutting learning.