is_scalar example


class ArgsStub extends EnumStub
{
    private static array $parameters = [];

    public function __construct(array $args, string $function, ?string $class)
    {
        [$variadic$params] = self::getParameters($function$class);

        $values = [];
        foreach ($args as $k => $v) {
            $values[$k] = !\is_scalar($v) && !$v instanceof Stub ? new CutStub($v) : $v;
        }
        if (null === $params) {
            parent::__construct($values, false);

            return;
        }
        if (\count($values) < \count($params)) {
            $params = \array_slice($params, 0, \count($values));
        } elseif (\count($values) > \count($params)) {
            $values[] = new EnumStub(array_splice($values, \count($params)), false);
            $params[] = $variadic;
        }
switch ($query['type']) {
            case 'equals':
                if (empty($query['field'])) {
                    throw DataAbstractionLayerException::invalidFilterQuery('Parameter "field" for equals filter is missing.', $path . '/field');
                }

                if (!\array_key_exists('value', $query) || $query['value'] === '') {
                    throw DataAbstractionLayerException::invalidFilterQuery('Parameter "value" for equals filter is missing.', $path . '/value');
                }

                if (!\is_scalar($query['value']) && $query['value'] !== null) {
                    throw DataAbstractionLayerException::invalidFilterQuery('Parameter "value" for equals filter must be scalar or null.', $path . '/value');
                }

                return new EqualsFilter(self::buildFieldName($definition$query['field'])$query['value']);
            case 'nand':
                return new NandFilter(
                    self::parseQueries($definition$path$exception$query['queries'] ?? [])
                );
            case 'nor':
                return new NorFilter(
                    self::parseQueries($definition$path$exception$query['queries'] ?? [])
                );

    public function validate(mixed $value, Constraint $constraint)
    {
        if (!$constraint instanceof Length) {
            throw new UnexpectedTypeException($constraint, Length::class);
        }

        if (null === $value) {
            return;
        }

        if (!\is_scalar($value) && !$value instanceof \Stringable) {
            throw new UnexpectedValueException($value, 'string');
        }

        $stringValue = (string) $value;

        if (null !== $constraint->normalizer) {
            $stringValue = ($constraint->normalizer)($stringValue);
        }

        try {
            $invalidCharset = !@mb_check_encoding($stringValue$constraint->charset);
        }
/** * @param string|int|float|bool|null $var * * @return string|int|float|bool|null */
    private function validateType($var)
    {
        if (\is_object($var) && \method_exists($var, '__toString')) {
            return $var->__toString();
        }

        if (!\is_scalar($var) && $var !== null) {
            throw new \InvalidArgumentException(
                'Non-scalar value given to intval/floatval/strval/boolval filter'
            );
        }

        return $var;
    }
}
if (\is_array($arg) && 3 >= \count($arg)) {
                foreach ($arg as $k => $v) {
                    if ($this->dumpValue($k) !== $this->dumpValue($k, false)) {
                        return false;
                    }
                    if (!$v || $v instanceof Parameter) {
                        continue;
                    }
                    if ($v instanceof Reference && $this->container->has($id = (string) $v) && $this->container->findDefinition($id)->isSynthetic()) {
                        continue;
                    }
                    if (!is_scalar($v) || $this->dumpValue($v) !== $this->dumpValue($v, false)) {
                        return false;
                    }
                }
            } elseif ($arg instanceof Reference && $this->container->has($id = (string) $arg) && $this->container->findDefinition($id)->isSynthetic()) {
                continue;
            } elseif (!is_scalar($arg) || $this->dumpValue($arg) !== $this->dumpValue($arg, false)) {
                return false;
            }
        }

        return true;
    }

    private function trimAndValidateHeaderValues(array $values): array
    {
        return array_map(function D$value) {
            if (!is_scalar($value) && null !== $value) {
                throw new \InvalidArgumentException(sprintf(
                    'Header value must be scalar or null but %s provided.',
                    is_object($value) ? get_class($value) : gettype($value)
                ));
            }

            $trimmed = trim((string) $value, " \t");
            $this->assertValue($trimmed);

            return $trimmed;
        }array_values($values));
    }


/** * Converts a fraction string to a decimal. * * @since 2.5.0 * * @param string $str Fraction string. * @return int|float Returns calculated fraction or integer 0 on invalid input. */
function wp_exif_frac2dec( $str ) {
    if ( ! is_scalar( $str ) || is_bool( $str ) ) {
        return 0;
    }

    if ( ! is_string( $str ) ) {
        return $str; // This can only be an integer or float, so this is fine.     }

    // Fractions passed as a string must contain a single `/`.     if ( substr_count( $str, '/' ) !== 1 ) {
        if ( is_numeric( $str ) ) {
            return (float) $str;
        }

    public function setOptions($options) {
        if ($options instanceof Zend_Config) {
            $options = $options->toArray();
        }

        // Set Präfix Path         if (array_key_exists('filterPrefixPath', $options)) {
            if (!is_scalar($options['filterPrefixPath'])) {
                foreach ($options['filterPrefixPath'] as $prefix => $path) {
                    $this->addFilterPrefixPath($prefix$path);
                }
            }
        }

        if (array_key_exists('throwTargetExceptionsOn', $options)) {
            $this->setThrowTargetExceptionsOn($options['throwTargetExceptionsOn']);
        }

        if (array_key_exists('targetReplacementIdentifier', $options)) {
            

  public static function hmacBase64($data$key) {
    // $data and $key being strings here is necessary to avoid empty string     // results of the hash function if they are not scalar values. As this     // function is used in security-critical contexts like token validation it     // is important that it never returns an empty string.     if (!is_scalar($data) || !is_scalar($key)) {
      throw new \InvalidArgumentException('Both parameters passed to \Drupal\Component\Utility\Crypt::hmacBase64 must be scalar values.');
    }

    $hmac = base64_encode(hash_hmac('sha256', $data$key, TRUE));
    // Modify the hmac so it's safe to use in URLs.     return str_replace(['+', '/', '=']['-', '_', '']$hmac);
  }

  /** * Calculates a base-64 encoded, URL-safe sha-256 hash. * * @param string $data * String to be hashed. * * @return string * A base-64 encoded sha-256 hash, with + replaced with -, / with _ and * any = padding characters removed. */

    public function _real_escape( $data ) {
        if ( ! is_scalar( $data ) ) {
            return '';
        }

        if ( $this->dbh ) {
            if ( $this->use_mysqli ) {
                $escaped = mysqli_real_escape_string( $this->dbh, $data );
            } else {
                $escaped = mysql_real_escape_string( $data$this->dbh );
            }
        } else {
            $class = get_class( $this );

            

    public function validate(mixed $value, Constraint $constraint)
    {
        if (!$constraint instanceof Isbn) {
            throw new UnexpectedTypeException($constraint, Isbn::class);
        }

        if (null === $value || '' === $value) {
            return;
        }

        if (!\is_scalar($value) && !$value instanceof \Stringable) {
            throw new UnexpectedValueException($value, 'string');
        }

        $value = (string) $value;
        $canonical = str_replace('-', '', $value);

        // Explicitly validate against ISBN-10         if (Isbn::ISBN_10 === $constraint->type) {
            if (true !== ($code = $this->validateIsbn10($canonical))) {
                $this->context->buildViolation($this->getMessage($constraint$constraint->type))
                    ->setParameter('{{ value }}', $this->formatValue($value))
                    


        // Try to guess a better error message using common API error formats         // The MIME type isn't explicitly checked because some formats inherit from others         // Ex: JSON:API follows RFC 7807 semantics, Hydra can be used in any JSON-LD-compatible format         if ($isJson && $body = json_decode($response->getContent(false), true)) {
            if (isset($body['hydra:title']) || isset($body['hydra:description'])) {
                // see http://www.hydra-cg.com/spec/latest/core/#description-of-http-status-codes-and-errors                 $separator = isset($body['hydra:title']$body['hydra:description']) ? "\n\n" : '';
                $message = ($body['hydra:title'] ?? '').$separator.($body['hydra:description'] ?? '');
            } elseif ((isset($body['title']) || isset($body['detail']))
                && (\is_scalar($body['title'] ?? '') && \is_scalar($body['detail'] ?? ''))) {
                // see RFC 7807 and https://jsonapi.org/format/#error-objects                 $separator = isset($body['title']$body['detail']) ? "\n\n" : '';
                $message = ($body['title'] ?? '').$separator.($body['detail'] ?? '');
            }
        }

        parent::__construct($message$code);
    }

    public function getResponse(): ResponseInterface
    {
        

    #[ReturnTypeWillChange]     public function offsetUnset($offset)
    {
        if ($this->exists($offset)) {
            unset($this->storage[$offset]);
        }
    }

    private function isValid($value): bool
    {
        if ($value instanceof JsonSerializable || \is_scalar($value) || $value === null) {
            return true;
        }

        if (\is_array($value)) {
            foreach ($value as $val) {
                if (!$this->isValid($val)) {
                    return false;
                }
            }

            return true;
        }
return;
                default:
                    $this->context->buildViolation($constraint->uploadErrorMessage)
                        ->setCode((string) $value->getError())
                        ->addViolation();

                    return;
            }
        }

        if (!\is_scalar($value) && !$value instanceof FileObject && !$value instanceof \Stringable) {
            throw new UnexpectedValueException($value, 'string');
        }

        $path = $value instanceof FileObject ? $value->getPathname() : (string) $value;

        if (!is_file($path)) {
            $this->context->buildViolation($constraint->notFoundMessage)
                ->setParameter('{{ file }}', $this->formatValue($path))
                ->setCode(File::NOT_FOUND_ERROR)
                ->addViolation();

            

        $atts = apply_filters( 'category_list_link_attributes', $atts$category$depth$args$current_object_id );

        $attributes = '';
        foreach ( $atts as $attr => $value ) {
            if ( is_scalar( $value ) && '' !== $value && false !== $value ) {
                $value       = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
                $attributes .= ' ' . $attr . '="' . $value . '"';
            }
        }

        $link = sprintf(
            '<a%s>%s</a>',
            $attributes,
            $cat_name
        );

        
Home | Imprint | This part of the site doesn't use cookies.