Doctrine\DBAL\Types\ConversionException::conversionFailedSerialization PHP Method

conversionFailedSerialization() public static method

public static conversionFailedSerialization ( $value, $format, $error )
    public static function conversionFailedSerialization($value, $format, $error)
    {
        $actualType = is_object($value) ? get_class($value) : gettype($value);
        return new self(sprintf("Could not convert PHP type '%s' to '%s', as an '%s' error was triggered by the serialization", $actualType, $format, $error));
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (null === $value) {
         return null;
     }
     $encoded = json_encode($value);
     if (JSON_ERROR_NONE !== json_last_error()) {
         throw ConversionException::conversionFailedSerialization($value, 'json', $this->getLastErrorMessage());
     }
     return $encoded;
 }