note 129766 added to function.unserialize
| From: | contact@needlecode.com | Date: | Tue, 24 Sep 2024 19:20:35 +0000 |
| Subject: | note 129766 added to function.unserialize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221549@lists.php.net to get a copy of this message | ||
/**
* Checks value to find if it was serialized.
*
* If $data is not a string, then returned value will always be false.
* Serialized data is always a string.
*
* @since 2.0.5
* @since 6.1.0 Added Enum support.
*
* @source wordpress
* @param string $data Value to check to see if was serialized.
* @param bool $strict Optional. Whether to be strict about the end of the string. Default true.
* @return bool False if not serialized and true if it was.
*/
function is_serialized( $data, $strict = true ) {
// If it isn't a string, it isn't serialized.
if ( ! is_string( $data ) ) {
return false;
}
$data = trim( $data );
if ( 'N;' === $data ) {
return true;
}
if ( strlen( $data ) < 4 ) {
return false;
}
if ( ':' !== $data[1] ) {
return false;
}
if ( $strict ) {
$lastc = substr( $data, -1 );
if ( ';' !== $lastc && '}' !== $lastc ) {
return false;
}
} else {
$semicolon = strpos( $data, ';' );
$brace = strpos( $data, '}' );
// Either ; or } must exist.
if ( false === $semicolon && false === $brace ) {
return false;
}
// But neither must be in the first X characters.
if ( false !== $semicolon && $semicolon < 3 ) {
return false;
}
if ( false !== $brace && $brace < 4 ) {
return false;
}
}
$token = $data[0];
switch ( $token ) {
case 's':
if ( $strict ) {
if ( '"' !== substr( $data, -2, 1 ) ) {
return false;
}
} elseif ( ! str_contains( $data, '"' ) ) {
return false;
}
// Or else fall through.
case 'a':
case 'O':
case 'E':
return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data );
case 'b':
case 'i':
case 'd':
$end = $strict ? '$' : '';
return (bool) preg_match( "/^{$token}:[0-9.E+-]+;$end/", $data );
}
return false;
}
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 37.111.220.178)
----
Manual Page -- https://php.net/manual/en/function.unserialize.php
Edit -- https://main.php.net/note/edit/129766
Del: integrated -- https://main.php.net/note/delete/129766/integrated
Del: useless -- https://main.php.net/note/delete/129766/useless
Del: bad code -- https://main.php.net/note/delete/129766/bad+code
Del: spam -- https://main.php.net/note/delete/129766/spam
Del: non-english -- https://main.php.net/note/delete/129766/non-english
Del: in docs -- https://main.php.net/note/delete/129766/in+docs
Del: other reasons-- https://main.php.net/note/delete/129766
Reject -- https://main.php.net/note/reject/129766
Search -- https://main.php.net/manage/user-notes.php