当前位置: 首页>>代码示例>>PHP>>正文


PHP gettype函数代码示例

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


在下文中一共展示了gettype函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: assertErrorsAreTriggered

 /**
  * @param int      $expectedType     Expected triggered error type (pass one of PHP's E_* constants)
  * @param string[] $expectedMessages Expected error messages
  * @param callable $testCode         A callable that is expected to trigger the error messages
  */
 public static function assertErrorsAreTriggered($expectedType, $expectedMessages, $testCode)
 {
     if (!is_callable($testCode)) {
         throw new \InvalidArgumentException(sprintf('The code to be tested must be a valid callable ("%s" given).', gettype($testCode)));
     }
     $e = null;
     $triggeredMessages = array();
     try {
         $prevHandler = set_error_handler(function ($type, $message, $file, $line, $context) use($expectedType, &$triggeredMessages, &$prevHandler) {
             if ($expectedType !== $type) {
                 return null !== $prevHandler && call_user_func($prevHandler, $type, $message, $file, $line, $context);
             }
             $triggeredMessages[] = $message;
         });
         call_user_func($testCode);
     } catch (\Exception $e) {
     } catch (\Throwable $e) {
     }
     restore_error_handler();
     if (null !== $e) {
         throw $e;
     }
     \PHPUnit_Framework_Assert::assertCount(count($expectedMessages), $triggeredMessages);
     foreach ($triggeredMessages as $i => $message) {
         \PHPUnit_Framework_Assert::assertContains($expectedMessages[$i], $message);
     }
 }
开发者ID:unexge,项目名称:symfony,代码行数:32,代码来源:ErrorAssert.php

示例3: 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

示例4: 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

示例5: prepareData

 /**
  * Serialize the data for storing.
  *
  * Serializes the given $data to a executable PHP code representation 
  * string. This works with objects implementing {@link ezcBaseExportable},
  * arrays and scalar values (int, bool, float, string). The return value is
  * executable PHP code to be stored to disk. The data can be unserialized 
  * using the {@link fetchData()} method.
  * 
  * @param mixed $data
  * @return string
  *
  * @throws ezcCacheInvalidDataException
  *         if the $data can not be serialized (e.g. an object that does not
  *         implement ezcBaseExportable, a resource, ...).
  */
 protected function prepareData($data)
 {
     if (is_object($data) && !$data instanceof ezcBaseExportable || is_resource($data)) {
         throw new ezcCacheInvalidDataException(gettype($data), array('simple', 'array', 'ezcBaseExportable'));
     }
     return "<?php\nreturn " . var_export($data, true) . ";\n?>\n";
 }
开发者ID:mdb-webdev,项目名称:livehelperchat,代码行数:23,代码来源:object.php

示例6: __construct

 /**
  * Constructor.
  *
  * @param string|number $value value to store in this numericNode
  * @throws \TYPO3\CMS\Fluid\Core\Parser\Exception
  */
 public function __construct($value)
 {
     if (!is_numeric($value)) {
         throw new \TYPO3\CMS\Fluid\Core\Parser\Exception('Numeric node requires an argument of type number, "' . gettype($value) . '" given.', 1360414192);
     }
     $this->value = $value + 0;
 }
开发者ID:rickymathew,项目名称:TYPO3.CMS,代码行数:13,代码来源:NumericNode.php

示例7: 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

示例8: __invoke

 /**
  * Configures the view resolver.
  *
  * @param \Es\Modules\ModulesEvent $event The modules event
  *
  * @throws \UnexpectedValueException If configuration has invalid
  *                                   specification of view resolver
  */
 public function __invoke(ModulesEvent $event)
 {
     $modules = $this->getModules();
     $resolver = $this->getResolver();
     foreach ($modules as $name => $module) {
         $resolver->registerModulePath($name, $module->getModuleDir());
     }
     $config = $this->getConfig();
     if (!isset($config['view']['resolver'])) {
         return;
     }
     $map = (array) $config['view']['resolver'];
     foreach ($map as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $template => $path) {
                 if (!is_string($path)) {
                     throw new UnexpectedValueException(sprintf('Invalid specification of view resolver for "%s" ' . 'provided; the path of template "%s" must be an ' . 'string, "%s" received.', $key, $template, is_object($path) ? get_class($path) : gettype($path)));
                 }
                 $template = Resolver::getFullTemplateName($key, $template);
                 $resolver->registerTemplatePath($template, $path);
             }
         } elseif (is_string($value)) {
             $resolver->registerTemplatePath($key, $value);
         } else {
             throw new UnexpectedValueException(sprintf('Invalid specification of view resolver provided; ' . '"%s" must be an string or an array, "%s" received.', $key, is_object($value) ? get_class($value) : gettype($value)));
         }
     }
 }
开发者ID:easy-system,项目名称:es-view,代码行数:36,代码来源:ConfigureResolverListener.php

示例9: 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

示例10: __construct

 public function __construct($var)
 {
     if (!is_object($var)) {
         throw new \RuntimeException('Argument 1 passed to ' . get_class($this) . ' must be an object, var of type ' . gettype($var) . ' given');
     }
     $this->storage = $var;
 }
开发者ID:tacone,项目名称:datasource,代码行数:7,代码来源:AbstractEloquentDataSource.php

示例11: json_nukeempty

function json_nukeempty(&$data)
{
    if (gettype($data) == 'object') {
        $data = get_object_vars($data);
    }
    if (!is_array($data)) {
        return;
    }
    foreach ($data as $key => $dummy) {
        if (gettype($data[$key]) == 'string') {
            if ($dummy === "") {
                unset($data[$key]);
            }
            continue;
        }
        if (gettype($data[$key]) == 'object') {
            $data[$key] = get_object_vars($data[$key]);
        }
        if (!is_array($data[$key])) {
            continue;
        }
        if (count($data[$key]) > 0) {
            json_nukeempty($data[$key]);
        }
        if (count($data[$key]) == 0) {
            unset($data[$key]);
        }
    }
}
开发者ID:patrickz98,项目名称:xavaro,代码行数:29,代码来源:json.php

示例12: checkType

 /**
  * Check if $value is a Stylesheet object.
  * 
  * @throws InvalidArgumentException If $value is not a Stylesheet object.
  */
 protected function checkType($value)
 {
     if (!$value instanceof Stylesheet) {
         $msg = "StylesheetCollection class only accept Stylesheet objects, '" . gettype($value) . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }
开发者ID:swapnilaptara,项目名称:tao-aptara-assess,代码行数:12,代码来源:StylesheetCollection.php

示例13: getSignatureForEachMethodByMulticall

 /**
  * Attempt to get the method signatures in one request via system.multicall().
  * This is a boxcar feature of XML-RPC and is found on fewer servers.  However,
  * can significantly improve performance if present.
  *
  * @param  array $methods
  * @return array array(array(return, param, param, param...))
  */
 public function getSignatureForEachMethodByMulticall($methods = null)
 {
     if ($methods === null) {
         $methods = $this->listMethods();
     }
     $multicallParams = array();
     foreach ($methods as $method) {
         $multicallParams[] = array('methodName' => 'system.methodSignature', 'params' => array($method));
     }
     $serverSignatures = $this->_system->multicall($multicallParams);
     if (!is_array($serverSignatures)) {
         $type = gettype($serverSignatures);
         $error = "Multicall return is malformed.  Expected array, got {$type}";
         require_once 'Zend/XmlRpc/Client/IntrospectException.php';
         throw new Zend_XmlRpc_Client_IntrospectException($error);
     }
     if (count($serverSignatures) != count($methods)) {
         $error = 'Bad number of signatures received from multicall';
         require_once 'Zend/XmlRpc/Client/IntrospectException.php';
         throw new Zend_XmlRpc_Client_IntrospectException($error);
     }
     // Create a new signatures array with the methods name as keys and the signature as value
     $signatures = array();
     foreach ($serverSignatures as $i => $signature) {
         $signatures[$methods[$i]] = $signature;
     }
     return $signatures;
 }
开发者ID:andrelsguerra,项目名称:pequiambiental,代码行数:36,代码来源:ServerIntrospection.php

示例14: memoize

/**
 * Memoizes callbacks and returns their value instead of calling them
 *
 * @param callable $callback Callable closure or function
 * @param array $arguments Arguments
 * @param array|string $key Optional memoize key to override the auto calculated hash
 * @return mixed
 */
function memoize($callback, array $arguments = array(), $key = null)
{
    static $storage = array();
    if ($callback === null) {
        $storage = array();
        return null;
    }
    InvalidArgumentException::assertCallback($callback, __FUNCTION__, 1);
    static $keyGenerator = null;
    if (!$keyGenerator) {
        $keyGenerator = function ($value) use(&$keyGenerator) {
            $type = gettype($value);
            if ($type === 'array') {
                $key = join(':', map($value, $keyGenerator));
            } elseif ($type === 'object') {
                $key = get_class($value) . ':' . spl_object_hash($value);
            } else {
                $key = (string) $value;
            }
            return $key;
        };
    }
    if ($key === null) {
        $key = $keyGenerator(array_merge(array($callback), $arguments));
    } else {
        $key = $keyGenerator($key);
    }
    if (!isset($storage[$key]) && !array_key_exists($key, $storage)) {
        $storage[$key] = call_user_func_array($callback, $arguments);
    }
    return $storage[$key];
}
开发者ID:RightThisMinute,项目名称:responsive-images-php,代码行数:40,代码来源:Memoize.php

示例15: __construct

 /**
  * Constructor
  *
  * Add a default initializer to ensure the plugin is valid after instance
  * creation.
  *
  * Additionally, the constructor provides forwards compatibility with v3 by
  * overloading the initial argument. v2 usage expects either null or a
  * ConfigInterface instance, and will ignore any other arguments. v3 expects
  * a ContainerInterface instance, and will use an array of configuration to
  * seed the current instance with services. In most cases, you can ignore the
  * constructor unless you are writing a specialized factory for your plugin
  * manager or overriding it.
  *
  * @param null|ConfigInterface|ContainerInterface $configOrContainerInstance
  * @param array $v3config If $configOrContainerInstance is a container, this
  *     value will be passed to the parent constructor.
  * @throws Exception\InvalidArgumentException if $configOrContainerInstance
  *     is neither null, nor a ConfigInterface, nor a ContainerInterface.
  */
 public function __construct($configOrContainerInstance = null, array $v3config = [])
 {
     if (null !== $configOrContainerInstance && !$configOrContainerInstance instanceof ConfigInterface && !$configOrContainerInstance instanceof ContainerInterface) {
         throw new Exception\InvalidArgumentException(sprintf('%s expects a ConfigInterface instance or ContainerInterface instance; received %s', get_class($this), is_object($configOrContainerInstance) ? get_class($configOrContainerInstance) : gettype($configOrContainerInstance)));
     }
     if ($configOrContainerInstance instanceof ContainerInterface) {
         if (property_exists($this, 'serviceLocator')) {
             if (!empty($v3config)) {
                 parent::__construct(new Config($v3config));
             }
             $this->serviceLocator = $configOrContainerInstance;
         }
         if (property_exists($this, 'creationContext')) {
             if (!empty($v3config)) {
                 parent::__construct($v3config);
             }
             $this->creationContext = $configOrContainerInstance;
         }
     }
     if ($configOrContainerInstance instanceof ConfigInterface) {
         parent::__construct($configOrContainerInstance);
     }
     $this->addInitializer(function ($instance) {
         if ($instance instanceof ServiceLocatorAwareInterface) {
             $instance->setServiceLocator($this);
         }
     });
 }
开发者ID:baardbaard,项目名称:bb-twitterfeed,代码行数:48,代码来源:AbstractPluginManager.php


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