Check to see if a string is serialized?

前端 未结 11 1677
情歌与酒
情歌与酒 2020-11-29 17:16

What\'s the best way to determine whether or not a string is the result of the serialize() function?

https://www.php.net/manual/en/function.serialize

11条回答
  •  无人及你
    2020-11-29 18:12

    Despite Pascal MARTIN's excellent answer, I was curious if you could approach this another way, so I did this just as a mental exercise

    ';
      echo $valueToUnserialize;
    } else {
      echo 'Value was unserialized!
    '; var_dump( $unserialized ); }

    And it actually works. The only caveat is that it will likely break if you have a registered error handler because of how $php_errormsg works.

提交回复
热议问题