Assert\Assertion::scalar PHP Method

scalar() public static method

Assert that value is a PHP scalar
public static scalar ( mixed $value, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$message string | null
$propertyPath string | null
return boolean
    public static function scalar($value, $message = null, $propertyPath = null)
    {
        if (!is_scalar($value)) {
            $message = sprintf($message ?: 'Value "%s" is not a scalar.', static::stringify($value));
            throw static::createException($value, $message, static::INVALID_SCALAR, $propertyPath);
        }
        return true;
    }

Usage Example

Exemplo n.º 1
0
 public function testValidScalar()
 {
     Assertion::scalar("foo");
     Assertion::scalar(52);
     Assertion::scalar(12.34);
     Assertion::scalar(false);
 }
All Usage Examples Of Assert\Assertion::scalar