|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-06-29 07:08 UTC] lucas at threeamdesign dot com dot au
Description: ------------ I'm aware that the docs have this to say: --- Warning FALSE is returned both in the case of an error and if unserializing the serialized FALSE value. It is possible to catch this special case by comparing str with serialize(false) or by catching the issued E_NOTICE. --- Using the return value for failure and data is just lazy. This problem could be done away with, very easily if unserialize() were changed to accept a second parameter. This parameter would be a reference variable. If the function was called with the second parameter, the reference would be filled with either the unserialized data, or the success/failure boolean of the process. The return value of the function would then be the other. The latter form would be most backwards-compatible though seems more unintuitive. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 03:00:01 2025 UTC |
We could potentially make it throw an Exception with the whole Engine Exceptions transition going on. But it would break BC as you would have to write code like: try { $s = unserialize('something invalid'); } catch(Exception $e) { echo $e->getMessage(); } vs. if(!($s = @unserialize('something invalid'))) { echo 'Error: Unable to un-serialize'; }My point is $data = unserialize('something invalid', $unserialized); if (!$unserialized) { //handle error } or if (!unserialize('something invalid', $data)) { //handle error } would be far more reliable, and obviate the need for error handling/suppression.We currently have this function funserialize($serialized, &$into) { static $sfalse; if (is_string($serialized)) { if ($sfalse === null) { $sfalse = serialize(false); } $into = @unserialize($serialized); return $into !== false || rtrim($serialized) === $sfalse; } $into = false; return false; } but this is convoluted and isn't guaranteed to be future-proof.