// make sure to include the namespace when casting
$className = "SomeNameSpaceSomeClassName";
$classNameLength = strlen( $className );
$castedItem = unserialize(
preg_replace(
'/^O:d+:"[^"]++"/',
"O:$classNameLength:"$className"",
serialize( $item )
)
)
TYPECASTING IN PHP: The meaning of type casting is to use the value of a variable with different data type. In other word typecasting is a way to utilize one data type variable into the different data type. ... In PHP variables automatically decide the data type on the basis of the value assignment or context.