Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'd say, try to <a href="http://php.net/unserialize" rel="noreferrer"><code>unserialize</code></a> it ;-)</p> <p>Quoting the manual :</p> <blockquote> <p>In case the passed string is not unserializeable, FALSE is returned and E_NOTICE is issued.</p> </blockquote> <p>So, you have to check if the return value is <code>false</code> or not <em>(with <code>===</code> or <code>!==</code>, to be sure not to have any problem with <code>0</code> or <code>null</code> or anything that equals to <code>false</code>, I'd say)</em>.</p> <p>Just beware the notice : you might want/need to use the <a href="http://www.php.net/manual/en/language.operators.errorcontrol.php" rel="noreferrer">@ operator</a>.</p> <p>For instance :</p> <pre><code>$str = 'hjkl'; $data = @unserialize($str); if ($data !== false) { echo "ok"; } else { echo "not ok"; } </code></pre> <p>Will get you :</p> <pre><code>not ok </code></pre> <p><br> EDIT : Oh, and like @Peter said (thanks to him!), you might run into trouble if you are trying to unserialize the representation of a boolean false :-(</p> <p>So, checking that your serialized string is not equal to "<code>b:0;</code>" might be helpful too ; something like this should do the trick, I suppose :</p> <pre><code>$data = @unserialize($str); if ($str === 'b:0;' || $data !== false) { echo "ok"; } else { echo "not ok"; } </code></pre> <p>testing that special case before trying to unserialize would be an optimization -- but probably not that usefull, if you don't often have a false serialized value.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload