cs278/serialization-helpers
Composer 安装命令:
composer require cs278/serialization-helpers
包简介
Helpers to work with serialized strings
README 文档
README
Helpers for dealing with strings created by the serialize() function in PHP.
Usage
isSerialized($value) — Test if a supplied value is a PHP serialized string,
returns true iff the syntax looks correct. This function may produce false
negatives because Zend PHP’s unserialize() implementation will work on
malformed strings.
isSerialized($value, &$result) — As above but also returns the unserialized
value by reference.
unserialize($input) — Converts the serialized input into a PHP data type,
returns the resulting data type. If an error occurs during the unserialize
operation a SyntaxError will be thrown.
Examples
Test if a value is serialized:
isSerialized($value)
<?php use Cs278\SerializationHelpers\isSerialized; isSerialized('b:1'); // bool(false) isSerialized('d:2.71828'); // bool(true)
Unserialize with error handling:
<?php use Cs278\SerializationHelpers\unserialize; use Cs278\SerializationHelpers\Exception\SyntaxError; try { return unserialize('s:"foobar";'); } catch (SyntaxError $e) { $logger->warning('Input, `{input}` was not valid serialized data', array( 'input' => $e->getInput(), )); return null; }
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-01-30