• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP is_scalar函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中is_scalar函数的典型用法代码示例。如果您正苦于以下问题:PHP is_scalar函数的具体用法?PHP is_scalar怎么用?PHP is_scalar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了is_scalar函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: convert_uudecode

 function convert_uudecode($string)
 {
     // Sanity check
     if (!is_scalar($string)) {
         user_error('convert_uuencode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING);
         return false;
     }
     if (strlen($string) < 8) {
         user_error('convert_uuencode() The given parameter is not a valid uuencoded string', E_USER_WARNING);
         return false;
     }
     $decoded = '';
     foreach (explode("\n", $string) as $line) {
         $c = count($bytes = unpack('c*', substr(trim($line), 1)));
         while ($c % 4) {
             $bytes[++$c] = 0;
         }
         foreach (array_chunk($bytes, 4) as $b) {
             $b0 = $b[0] == 0x60 ? 0 : $b[0] - 0x20;
             $b1 = $b[1] == 0x60 ? 0 : $b[1] - 0x20;
             $b2 = $b[2] == 0x60 ? 0 : $b[2] - 0x20;
             $b3 = $b[3] == 0x60 ? 0 : $b[3] - 0x20;
             $b0 <<= 2;
             $b0 |= $b1 >> 4 & 0x3;
             $b1 <<= 4;
             $b1 |= $b2 >> 2 & 0xf;
             $b2 <<= 6;
             $b2 |= $b3 & 0x3f;
             $decoded .= pack('c*', $b0, $b1, $b2);
         }
     }
     return rtrim($decoded, "");
 }
开发者ID:poppen,项目名称:p2,代码行数:33,代码来源:convert_uudecode.php


示例2: setValue

 /**
  * Sets selected items (by keys).
  * @param  array
  * @return self
  */
 public function setValue($values)
 {
     if (is_scalar($values) || $values === NULL) {
         $values = (array) $values;
     } elseif (!is_array($values)) {
         throw new Nette\InvalidArgumentException(sprintf("Value must be array or NULL, %s given in field '%s'.", gettype($values), $this->name));
     }
     $flip = [];
     foreach ($values as $value) {
         if (!is_scalar($value) && !method_exists($value, '__toString')) {
             throw new Nette\InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", gettype($value), $this->name));
         }
         $flip[(string) $value] = TRUE;
     }
     $values = array_keys($flip);
     if ($this->checkAllowedValues && ($diff = array_diff($values, array_keys($this->items)))) {
         $set = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) {
             return var_export($s, TRUE);
         }, array_keys($this->items))), 70, '...');
         $vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
         throw new Nette\InvalidArgumentException("Value{$vals} are out of allowed set [{$set}] in field '{$this->name}'.");
     }
     $this->value = $values;
     return $this;
 }
开发者ID:jjanekk,项目名称:forms,代码行数:30,代码来源:MultiChoiceControl.php


示例3: __construct

 public function __construct($value)
 {
     if (!is_scalar($value) && null !== $value) {
         throw new InvalidNativeArgumentException($value, ['string', 'int', 'bool', 'null']);
     }
     $this->value = $value;
 }
开发者ID:bogdananton,项目名称:mysql-structure-inspect,代码行数:7,代码来源:FieldDefaultValue.php


示例4: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$constraint instanceof Length) {
         throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\Length');
     }
     if (null === $value || '' === $value) {
         return;
     }
     if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $stringValue = (string) $value;
     if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) {
         $length = grapheme_strlen($stringValue);
     } elseif (function_exists('mb_strlen')) {
         $length = mb_strlen($stringValue, $constraint->charset);
     } else {
         $length = strlen($stringValue);
     }
     if (null !== $constraint->max && $length > $constraint->max) {
         $this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)->setParameter('{{ value }}', $this->formatValue($stringValue))->setParameter('{{ limit }}', $constraint->max)->setInvalidValue($value)->setPlural((int) $constraint->max)->setCode(Length::TOO_LONG_ERROR)->addViolation();
         return;
     }
     if (null !== $constraint->min && $length < $constraint->min) {
         $this->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->minMessage)->setParameter('{{ value }}', $this->formatValue($stringValue))->setParameter('{{ limit }}', $constraint->min)->setInvalidValue($value)->setPlural((int) $constraint->min)->setCode(Length::TOO_SHORT_ERROR)->addViolation();
     }
 }
开发者ID:scottleedavis,项目名称:hackazon,代码行数:30,代码来源:LengthValidator.php


示例5: validate

 public function validate($input)
 {
     if (!is_scalar($input)) {
         return false;
     }
     return (bool) preg_match($this->regex, $input);
 }
开发者ID:respect,项目名称:validation,代码行数:7,代码来源:Regex.php


示例6: convert_uuencode

 function convert_uuencode($string)
 {
     // Sanity check
     if (!is_scalar($string)) {
         user_error('convert_uuencode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING);
         return false;
     }
     $u = 0;
     $encoded = '';
     while ($c = count($bytes = unpack('c*', substr($string, $u, 45)))) {
         $u += 45;
         $encoded .= pack('c', $c + 0x20);
         while ($c % 3) {
             $bytes[++$c] = 0;
         }
         foreach (array_chunk($bytes, 3) as $b) {
             $b0 = ($b[0] & 0xfc) >> 2;
             $b1 = (($b[0] & 0x3) << 4) + (($b[1] & 0xf0) >> 4);
             $b2 = (($b[1] & 0xf) << 2) + (($b[2] & 0xc0) >> 6);
             $b3 = $b[2] & 0x3f;
             $b0 = $b0 ? $b0 + 0x20 : 0x60;
             $b1 = $b1 ? $b1 + 0x20 : 0x60;
             $b2 = $b2 ? $b2 + 0x20 : 0x60;
             $b3 = $b3 ? $b3 + 0x20 : 0x60;
             $encoded .= pack('c*', $b0, $b1, $b2, $b3);
         }
         $encoded .= "\n";
     }
     // Add termination characters
     $encoded .= "`\n";
     return $encoded;
 }
开发者ID:casan,项目名称:eccube-2_13,代码行数:32,代码来源:convert_uuencode.php


示例7: setValue

 public function setValue($values)
 {
     if (is_scalar($values) || $values === NULL) {
         $values = (array) $values;
     } elseif (!is_array($values)) {
         throw new Nette\InvalidArgumentException(sprintf("Value must be array or NULL, %s given in field '%s'.", gettype($values), $this->name));
     }
     $flip = array();
     foreach ($values as $value) {
         if (!is_scalar($value) && !method_exists($value, '__toString')) {
             throw new Nette\InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", gettype($value), $this->name));
         }
         $flip[(string) $value] = TRUE;
     }
     $values = array_keys($flip);
     $items = $this->items;
     $nestedKeys = array();
     array_walk_recursive($items, function ($value, $key) use(&$nestedKeys) {
         $nestedKeys[] = $key;
     });
     if ($diff = array_diff($values, $nestedKeys)) {
         $range = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) {
             return var_export($s, TRUE);
         }, $nestedKeys)), 70, '...');
         $vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
         throw new Nette\InvalidArgumentException("Value{$vals} are out of allowed range [{$range}] in field '{$this->name}'.");
     }
     $this->value = $values;
     return $this;
 }
开发者ID:krejcon3,项目名称:checkboxtree,代码行数:30,代码来源:CheckBoxTree.php


示例8: normalize

 protected function normalize($data)
 {
     if (null === $data || is_scalar($data)) {
         return $data;
     }
     if (is_array($data) || $data instanceof \Traversable) {
         $normalized = array();
         $count = 1;
         foreach ($data as $key => $value) {
             if ($count++ >= 1000) {
                 $normalized['...'] = 'Over 1000 items, aborting normalization';
                 break;
             }
             $normalized[$key] = $this->normalize($value);
         }
         return $normalized;
     }
     if ($data instanceof \DateTime) {
         return $data->format($this->dateFormat);
     }
     if (is_object($data)) {
         if ($data instanceof Exception) {
             return $this->normalizeException($data);
         }
         return sprintf("[object] (%s: %s)", get_class($data), $this->toJson($data, true));
     }
     if (is_resource($data)) {
         return '[resource]';
     }
     return '[unknown(' . gettype($data) . ')]';
 }
开发者ID:brasilmorar,项目名称:wordpress_4_1_1,代码行数:31,代码来源:NormalizerFormatter.php


示例9: bcinvert

 function bcinvert($a, $n)
 {
     // Sanity check
     if (!is_scalar($a)) {
         user_error('bcinvert() expects parameter 1 to be string, ' . gettype($a) . ' given', E_USER_WARNING);
         return false;
     }
     if (!is_scalar($n)) {
         user_error('bcinvert() expects parameter 2 to be string, ' . gettype($n) . ' given', E_USER_WARNING);
         return false;
     }
     $u1 = $v2 = '1';
     $u2 = $v1 = '0';
     $u3 = $n;
     $v3 = $a;
     while (bccomp($v3, '0')) {
         $q0 = bcdiv($u3, $v3);
         $t1 = bcsub($u1, bcmul($q0, $v1));
         $t2 = bcsub($u2, bcmul($q0, $v2));
         $t3 = bcsub($u3, bcmul($q0, $v3));
         $u1 = $v1;
         $u2 = $v2;
         $u3 = $v3;
         $v1 = $t1;
         $v2 = $t2;
         $v3 = $t3;
     }
     if (bccomp($u2, '0') < 0) {
         return bcadd($u2, $n);
     } else {
         return bcmod($u2, $n);
     }
 }
开发者ID:casan,项目名称:eccube-2_13,代码行数:33,代码来源:bcinvert.php


示例10: addValue

 /**
  * Add a single value to the Parameter
  * @param mixed $value 
  */
 public function addValue($value)
 {
     if (!is_scalar($value)) {
         throw new Exception('Only scalar values permitted');
     }
     $this->value[] = $value;
 }
开发者ID:CraigMason,项目名称:OAuth,代码行数:11,代码来源:Parameter.php


示例11: format

 /**
  * {@inheritdoc}
  */
 public function format(array $record)
 {
     $record = parent::format($record);
     if (!isset($record['datetime'], $record['message'], $record['level'])) {
         throw new \InvalidArgumentException('The record should at least contain datetime, message and level keys, ' . var_export($record, true) . ' given');
     }
     $message = new Message();
     $message->setTimestamp($record['datetime'])->setShortMessage((string) $record['message'])->setHost($this->systemName)->setLevel($this->logLevels[$record['level']]);
     if (isset($record['channel'])) {
         $message->setFacility($record['channel']);
     }
     if (isset($record['extra']['line'])) {
         $message->setLine($record['extra']['line']);
         unset($record['extra']['line']);
     }
     if (isset($record['extra']['file'])) {
         $message->setFile($record['extra']['file']);
         unset($record['extra']['file']);
     }
     foreach ($record['extra'] as $key => $val) {
         $message->setAdditional($this->extraPrefix . $key, is_scalar($val) ? $val : $this->toJson($val));
     }
     foreach ($record['context'] as $key => $val) {
         $message->setAdditional($this->contextPrefix . $key, is_scalar($val) ? $val : $this->toJson($val));
     }
     if (null === $message->getFile() && isset($record['context']['exception']['file'])) {
         if (preg_match("/^(.+):([0-9]+)\$/", $record['context']['exception']['file'], $matches)) {
             $message->setFile($matches[1]);
             $message->setLine($matches[2]);
         }
     }
     return $message;
 }
开发者ID:sonfordson,项目名称:Laravel-Fundamentals,代码行数:36,代码来源:GelfMessageFormatter.php


示例12: getDateTime

 /**
  * Converts a value to a DateTime.
  * Supports microseconds
  *
  * @throws InvalidArgumentException if $value is invalid
  * @param  mixed $value \DateTime|\MongoDate|int|float
  * @return \DateTime
  */
 public static function getDateTime($value)
 {
     $datetime = false;
     $exception = null;
     if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
         return $value;
     } elseif ($value instanceof \MongoDate) {
         $datetime = static::craftDateTime($value->sec, $value->usec);
     } elseif (is_numeric($value)) {
         $seconds = $value;
         $microseconds = 0;
         if (false !== strpos($value, '.')) {
             list($seconds, $microseconds) = explode('.', $value);
             $microseconds = (int) str_pad((int) $microseconds, 6, '0');
             // ensure microseconds
         }
         $datetime = static::craftDateTime($seconds, $microseconds);
     } elseif (is_string($value)) {
         try {
             $datetime = new \DateTime($value);
         } catch (\Exception $e) {
             $exception = $e;
         }
     }
     if ($datetime === false) {
         throw new \InvalidArgumentException(sprintf('Could not convert %s to a date value', is_scalar($value) ? '"' . $value . '"' : gettype($value)), 0, $exception);
     }
     return $datetime;
 }
开发者ID:Wizkunde,项目名称:mongodb-odm,代码行数:37,代码来源:DateType.php


示例13: getScalar

 /**
  * @param string $key
  * @param mixed$val
  *
  * @return mixed
  *
  * @throws InvalidArgumentException
  */
 protected function getScalar($key, $val)
 {
     if (!is_scalar($val) && !(is_object($val) && method_exists($val, '__toString'))) {
         throw new InvalidArgumentException(sprintf('%s must be a scalar or implement __toString got "%s".', $key, is_object($val) ? get_class($val) : gettype($val)));
     }
     return is_object($val) ? (string) $val : $val;
 }
开发者ID:ebidtech,项目名称:message,代码行数:15,代码来源:SimpleMessage.php


示例14: php_compat_bcpowmod

/**
 * Replace bcpowmod()
 *
 * @category    PHP
 * @package     PHP_Compat
 * @license     LGPL - http://www.gnu.org/licenses/lgpl.html
 * @copyright   2004-2007 Aidan Lister <[email protected]>, Arpad Ray <[email protected]>
 * @link        http://php.net/function.bcpowmod
 * @author      Sara Golemon <[email protected]>
 * @version     $Revision: 1.1 $
 * @since       PHP 5.0.0
 * @require     PHP 4.0.0 (user_error)
 */
function php_compat_bcpowmod($x, $y, $modulus, $scale = 0)
{
    // Sanity check
    if (!is_scalar($x)) {
        user_error('bcpowmod() expects parameter 1 to be string, ' . gettype($x) . ' given', E_USER_WARNING);
        return false;
    }
    if (!is_scalar($y)) {
        user_error('bcpowmod() expects parameter 2 to be string, ' . gettype($y) . ' given', E_USER_WARNING);
        return false;
    }
    if (!is_scalar($modulus)) {
        user_error('bcpowmod() expects parameter 3 to be string, ' . gettype($modulus) . ' given', E_USER_WARNING);
        return false;
    }
    if (!is_scalar($scale)) {
        user_error('bcpowmod() expects parameter 4 to be integer, ' . gettype($scale) . ' given', E_USER_WARNING);
        return false;
    }
    $t = '1';
    while (bccomp($y, '0')) {
        if (bccomp(bcmod($y, '2'), '0')) {
            $t = bcmod(bcmul($t, $x), $modulus);
            $y = bcsub($y, '1');
        }
        $x = bcmod(bcmul($x, $x), $modulus);
        $y = bcdiv($y, '2');
    }
    return $t;
}
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:43,代码来源:bcpowmod.php


示例15: variableName

 /**
  * Generate a variable name for a given object. 
  * 
  * 
  * * If $value is an object, the generated variable name
  * will be [$object-class-short-name]_$occurence in lower case e.g. 'point_0',
  * 'assessmenttest_3', ... 
  * 
  * * If $value is a PHP scalar value (not including the null value), the generated
  * variable name will be [gettype($value)]_$occurence e.g. 'string_1', 'boolean_0', ...
  * 
  * * If $value is an array, the generated variable name will be array_$occurence such as
  * 'array_0', 'array_2', ...
  * 
  * * If $value is the null value, the generated variable name will be nullvalue_$occurence
  * such as 'nullvalue_3'.
  * 
  * * Finally, if the $value cannot be handled by this method, an InvalidArgumentException
  * is thrown.
  * 
  * @param mixed $value A value.
  * @param integer $occurence An occurence number.
  * @return string A variable name.
  * @throws InvalidArgumentException If $occurence is not a positive integer or if $value cannot be handled by this method.
  */
 public static function variableName($value, $occurence = 0)
 {
     if (is_int($occurence) === false || $occurence < 0) {
         $msg = "The 'occurence' argument must be a positive integer (>= 0).";
         throw new InvalidArgumentException($msg);
     }
     if (is_object($value) === true) {
         $object = new ReflectionObject($value);
         $className = mb_strtolower($object->getShortName(), 'UTF-8');
         return "{$className}_{$occurence}";
     } else {
         // Is it a PHP scalar value?
         if (is_scalar($value) === true) {
             return gettype($value) . '_' . $occurence;
         } else {
             if (is_array($value) === true) {
                 return 'array_' . $occurence;
             } else {
                 if (is_null($value) === true) {
                     return 'nullvalue_' . $occurence;
                 } else {
                     $msg = "Cannot handle the given value.";
                     throw new InvalidArgumentException($msg);
                 }
             }
         }
     }
 }
开发者ID:swapnilaptara,项目名称:tao-aptara-assess,代码行数:53,代码来源:Utils.php


示例16: createFieldValue

 protected function createFieldValue($typeMeta, $key, $value)
 {
     $result = null;
     $expectedType = $typeMeta->getType();
     if (is_scalar($value) || is_null($value) || $expectedType === "polymorphic") {
         $result = $value;
     } elseif (is_array($value)) {
         if ($typeMeta->isObjectType() && $typeMeta->isListType()) {
             $result = [];
             foreach ($value as $listValue) {
                 $childObj = $this->objectMetaService->createObject($typeMeta->getTargetClass());
                 $this->fill($childObj, $listValue);
                 $result[] = $childObj;
             }
         } elseif (in_array($expectedType, ["array", "entity", "entitylist"])) {
             $result = $value;
         } else {
             throw new InvalidObjectValueException(sprintf(Translate::t("Invalid value for the `%s` property."), $key));
         }
     } elseif (is_object($value)) {
         if ($expectedType === "map") {
             $result = (array) $value;
         } else {
             if (!$typeMeta->isObjectType()) {
                 throw new InvalidObjectValueException(sprintf(Translate::t("Invalid value for the `%s` property."), $key));
             }
             $result = $this->objectMetaService->createObject($typeMeta->getTargetClass());
             $this->fill($result, $value);
         }
     }
     return $result;
 }
开发者ID:agitation,项目名称:api-bundle,代码行数:32,代码来源:AbstractObjectService.php


示例17: dump

 /**
  * Dumps a node or array.
  *
  * @param array|PHPParser_Node $node Node or array to dump
  *
  * @return string Dumped value
  */
 public function dump($node)
 {
     if ($node instanceof PHPParser_Node) {
         $r = $node->getType() . '(';
     } elseif (is_array($node)) {
         $r = 'array(';
     } else {
         throw new InvalidArgumentException('Can only dump nodes and arrays.');
     }
     foreach ($node as $key => $value) {
         $r .= "\n" . '    ' . $key . ': ';
         if (null === $value) {
             $r .= 'null';
         } elseif (false === $value) {
             $r .= 'false';
         } elseif (true === $value) {
             $r .= 'true';
         } elseif (is_scalar($value)) {
             $r .= $value;
         } else {
             $r .= str_replace("\n", "\n" . '    ', $this->dump($value));
         }
     }
     return $r . "\n" . ')';
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:32,代码来源:NodeDumper.php


示例18: setProductName

 public function setProductName($productName)
 {
     if (!is_scalar($productName)) {
         throw new \InvalidArgumentException('Invalid name');
     }
     $this->productName = $productName;
 }
开发者ID:jammersonf,项目名称:ocp,代码行数:7,代码来源:Product.php


示例19: validateData

 /**
  * Validate data for autocompletion
  *
  * @param  mixed $data
  * @return bool
  */
 public function validateData($data)
 {
     if (!is_array($data) && !is_scalar($data)) {
         return false;
     }
     return true;
 }
开发者ID:crodriguezn,项目名称:crossfit-milagro,代码行数:13,代码来源:AutoCompleteScriptaculous.php


示例20: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$constraint instanceof Date) {
         throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\Date');
     }
     if (null === $value || '' === $value || $value instanceof \DateTime) {
         return;
     }
     if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
         throw new UnexpectedTypeException($value, 'string');
     }
     $value = (string) $value;
     if (!preg_match(static::PATTERN, $value, $matches)) {
         if ($this->context instanceof ExecutionContextInterface) {
             $this->context->buildViolation($constraint->message)->setParameter('{{ value }}', $this->formatValue($value))->setCode(Date::INVALID_FORMAT_ERROR)->addViolation();
         } else {
             $this->buildViolation($constraint->message)->setParameter('{{ value }}', $this->formatValue($value))->setCode(Date::INVALID_FORMAT_ERROR)->addViolation();
         }
         return;
     }
     if (!self::checkDate($matches[1], $matches[2], $matches[3])) {
         if ($this->context instanceof ExecutionContextInterface) {
             $this->context->buildViolation($constraint->message)->setParameter('{{ value }}', $this->formatValue($value))->setCode(Date::INVALID_DATE_ERROR)->addViolation();
         } else {
             $this->buildViolation($constraint->message)->setParameter('{{ value }}', $this->formatValue($value))->setCode(Date::INVALID_DATE_ERROR)->addViolation();
         }
     }
 }
开发者ID:neteasy-work,项目名称:hkgbf_crm,代码行数:31,代码来源:DateValidator.php



注:本文中的is_scalar函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP is_search函数代码示例发布时间:2022-05-15
下一篇:
PHP is_safe_capability函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap