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

conversionFailedInvalidType() public static method

Thrown when the PHP value passed to the converter was not of the expected type.
public static conversionFailedInvalidType ( mixed $value, string $toType, array $possibleTypes ) : ConversionException
$value mixed
$toType string
$possibleTypes array
return ConversionException
    public static function conversionFailedInvalidType($value, $toType, array $possibleTypes)
    {
        $actualType = is_object($value) ? get_class($value) : gettype($value);
        if (is_scalar($value)) {
            return new self(sprintf("Could not convert PHP value '%s' of type '%s' to type '%s'. Expected one of the following types: %s", $value, $actualType, $toType, implode(', ', $possibleTypes)));
        }
        return new self(sprintf("Could not convert PHP value of type '%s' to type '%s'. Expected one of the following types: %s", $actualType, $toType, implode(', ', $possibleTypes)));
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (null === $value) {
         return $value;
     }
     if ($value instanceof \DateTime) {
         return $value->format($platform->getTimeFormatString());
     }
     throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']);
 }
All Usage Examples Of Doctrine\DBAL\Types\ConversionException::conversionFailedInvalidType