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


PHP cast函数代码示例

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


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

示例1: verify

 /**
  * Executes this check
  *
  * @param   xp.compiler.ast.Node node
  * @param   xp.compiler.types.Scope scope
  * @return  bool
  */
 public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
 {
     $field = \cast($node, 'xp.compiler.ast.FieldNode');
     if ($scope->declarations[0] instanceof \xp\compiler\ast\InterfaceNode) {
         return ['I403', 'Interfaces may not have field declarations'];
     }
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:14,代码来源:FieldsVerification.class.php

示例2: verify

 /**
  * Executes this check
  *
  * @param   xp.compiler.ast.Node node
  * @param   xp.compiler.types.Scope scope
  * @return  bool
  */
 public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
 {
     $a = \cast($node, 'xp.compiler.ast.AssignmentNode');
     if (!$this->isWriteable($a->variable)) {
         return ['A403', 'Cannot assign to ' . ($a->variable instanceof \lang\Generic ? nameof($a->variable) : \xp::stringOf($a->variable)) . 's'];
     }
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:14,代码来源:IsAssignable.class.php

示例3: verify

 /**
  * Executes this check
  *
  * @param   xp.compiler.ast.Node node
  * @param   xp.compiler.types.Scope scope
  * @return  bool
  */
 public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
 {
     $member = \cast($node, 'xp.compiler.ast.RoutineNode');
     if (!isset($member->comment) && !$scope->declarations[0]->synthetic) {
         return ['D201', 'No api doc for member ' . $scope->declarations[0]->name->compoundName() . '::' . $member->getName()];
     }
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:14,代码来源:TypeMemberHasDocumentation.class.php

示例4: verify

 /**
  * Executes this check
  *
  * @param   xp.compiler.ast.Node node
  * @param   xp.compiler.types.Scope scope
  * @return  bool
  */
 public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
 {
     $access = \cast($node, 'xp.compiler.ast.ArrayAccessNode');
     $type = $scope->typeOf($access->target);
     $result = TypeName::$VAR;
     $message = null;
     if ($type->isArray()) {
         $result = $type->arrayComponentType();
     } else {
         if ($type->isMap()) {
             $result = $type->mapComponentType();
         } else {
             if ($type->isClass()) {
                 $ptr = new TypeInstance($scope->resolveType($type));
                 if ($ptr->hasIndexer()) {
                     $result = $ptr->getIndexer()->type;
                 } else {
                     $message = ['T305', 'Type ' . $ptr->name() . ' does not support offset access'];
                 }
             } else {
                 if ($type->isVariable()) {
                     $message = ['T203', 'Array access (var)' . $access->hashCode() . ' verification deferred until runtime'];
                 } else {
                     if ('string' === $type->name) {
                         $result = $type;
                     } else {
                         $message = ['T305', 'Using array-access on unsupported type ' . $type->toString()];
                     }
                 }
             }
         }
     }
     $scope->setType($access, $result);
     return $message;
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:42,代码来源:ArrayAccessVerification.class.php

示例5: verify

 /**
  * Executes this check
  *
  * @param   xp.compiler.ast.Node node
  * @param   xp.compiler.types.Scope scope
  * @return  bool
  */
 public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
 {
     $routine = \cast($node, 'xp.compiler.ast.PropertyNode');
     if ($scope->declarations[0] instanceof \xp\compiler\ast\InterfaceNode) {
         return ['I403', 'Interfaces may not have properties'];
     }
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:14,代码来源:PropertiesVerification.class.php

示例6: verify

 /**
  * Executes this check
  *
  * @param   xp.compiler.ast.Node node
  * @param   xp.compiler.types.Scope scope
  * @return  bool
  */
 public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
 {
     $routine = \cast($node, 'xp.compiler.ast.RoutineNode');
     $qname = $scope->declarations[0]->name->compoundName() . '::' . $routine->getName();
     $empty = $routine->body === null;
     if ($scope->declarations[0] instanceof \xp\compiler\ast\InterfaceNode) {
         if (!$empty) {
             return ['R403', 'Interface methods may not have a body ' . $qname];
         } else {
             if ($routine->modifiers !== MODIFIER_PUBLIC && $routine->modifiers !== 0) {
                 return ['R401', 'Interface methods may only be public ' . $qname];
             }
         }
     } else {
         if (Modifiers::isAbstract($routine->modifiers) && !$empty) {
             return ['R403', 'Abstract methods may not have a body ' . $qname];
         } else {
             if (!Modifiers::isAbstract($routine->modifiers) && $empty) {
                 return ['R401', 'Non-abstract methods must have a body ' . $qname];
             }
         }
         if ($routine->extension && !Modifiers::isStatic($routine->modifiers)) {
             return ['E403', 'Extension methods must be static ' . $qname];
         }
     }
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:33,代码来源:RoutinesVerification.class.php

示例7: verify

 /**
  * Executes this check
  *
  * @param   xp.compiler.ast.Node node
  * @param   xp.compiler.types.Scope scope
  * @return  bool
  */
 public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
 {
     $decl = \cast($node, 'xp.compiler.ast.TypeDeclarationNode');
     if (!isset($decl->comment) && !$decl->synthetic) {
         return ['D201', 'No api doc for type ' . $decl->name->compoundName()];
     }
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:14,代码来源:TypeHasDocumentation.class.php

示例8: verify

 /**
  * Executes this check
  *
  * @param   xp.compiler.ast.Node node
  * @param   xp.compiler.types.Scope scope
  * @return  bool
  */
 public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
 {
     $access = \cast($node, 'xp.compiler.ast.MemberAccessNode');
     // Verify type
     // * var: Might have method
     // * primitive, array, map, int: Definitely don't have fields
     $type = $scope->typeOf($access->target);
     if ($type->isVariable()) {
         return ['T203', 'Member access (var).' . $access->name . '() verification deferred until runtime'];
     } else {
         if (!$type->isClass()) {
             return ['T305', 'Using member access on unsupported type ' . $type->compoundName()];
         }
     }
     // Verify target method exists
     $target = new \xp\compiler\types\TypeInstance($scope->resolveType($type));
     if ($target->hasField($access->name)) {
         $member = $target->getField($access->name);
     } else {
         if ($target->hasProperty($access->name)) {
             $member = $target->getProperty($access->name);
         } else {
             return ['T404', 'No such field $' . $access->name . ' in ' . $target->name()];
         }
     }
     // Verify visibility
     if (!($member->modifiers & MODIFIER_PUBLIC)) {
         $enclosing = $scope->resolveType($scope->declarations[0]->name);
         if ($member->modifiers & MODIFIER_PRIVATE && !$enclosing->equals($target) || $member->modifiers & MODIFIER_PROTECTED && !($enclosing->equals($target) || $enclosing->isSubclassOf($target))) {
             return ['T403', sprintf('Accessing %s %s::$%s from %s', implode(' ', \lang\reflect\Modifiers::namesOf($member->modifiers)), $target->name(), $member->name, $enclosing->name())];
         }
     }
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:40,代码来源:MemberAccessVerification.class.php

示例9: verify

 /**
  * Executes this check
  *
  * @param   xp.compiler.ast.Node node
  * @param   xp.compiler.types.Scope scope
  * @return  bool
  */
 public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
 {
     $v = \cast($node, 'xp.compiler.ast.VariableNode');
     if (!$scope->getType($v)) {
         return ['V404', 'Uninitialized variable ' . $v->name];
     }
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:14,代码来源:UninitializedVariables.class.php

示例10: code

 /** @return string */
 public function code()
 {
     $r = '';
     foreach ($this->nodes as $node) {
         $r .= "\n" . cast($node, 'net.daringfireball.markdown.Text')->value;
     }
     return substr($r, 1);
 }
开发者ID:xp-forge,项目名称:markdown,代码行数:9,代码来源:CodeBlock.class.php

示例11: verify

 /**
  * Executes this check
  *
  * @param   xp.compiler.ast.Node node
  * @param   xp.compiler.types.Scope scope
  * @return  bool
  */
 public function verify(\xp\compiler\ast\Node $node, \xp\compiler\types\Scope $scope)
 {
     $arm = cast($node, 'xp.compiler.ast.ArmNode');
     foreach ($arm->initializations as $i => $init) {
         $type = $scope->resolveType($scope->typeOf($init), false);
         if (!$type->isSubclassOf(self::$closeable)) {
             return ['A403', 'Type ' . $type->name() . ' for assignment #' . ($i + 1) . ' in ARM block is not closeable'];
         }
     }
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:17,代码来源:ArmTypesAreCloseable.class.php

示例12: expanding

 /**
  * Add expansion `${kind.X}` with a given expansion function `f(X)`
  *
  * @param  string $kind
  * @param  [:var]|function(string): string $expansion
  * @return self
  */
 public function expanding($kind, $expansion)
 {
     $this->expansion = $this->expansion ?: clone self::$env;
     if ($expansion instanceof \ArrayAccess || is_array($expansion) && 0 !== key($expansion)) {
         $func = function ($name) use($expansion) {
             return isset($expansion[$name]) ? $expansion[$name] : null;
         };
     } else {
         $func = cast($expansion, 'function(string): string');
     }
     $this->expansion->expand($kind, $func);
     return $this;
 }
开发者ID:xp-framework,项目名称:core,代码行数:20,代码来源:Properties.class.php

示例13: loader

/**
 * Loader
 *
 * @param array $attr
 * @param array $item
 *
 * @return mixed
 */
function loader(array $attr, array $item)
{
    $item[$attr['id']] = cast($attr, $item[$attr['id']] ?? null);
    $callback = fqn('loader_' . $attr['type']);
    if (is_callable($callback)) {
        return $callback($attr, $item);
    }
    // @todo
    if ($attr['backend'] === 'json') {
        return loader_json($attr, $item);
    }
    return $item[$attr['id']];
}
开发者ID:akilli,项目名称:qnd,代码行数:21,代码来源:loader.php

示例14: optimize

 /**
  * Optimize a given node
  *
  * @param   xp.compiler.ast.Node in
  * @param   xp.compiler.types.Scope scope
  * @param   xp.compiler.optimize.Optimizations optimizations
  * @param   xp.compiler.ast.Node optimized
  */
 public function optimize(\xp\compiler\ast\Node $in, \xp\compiler\types\Scope $scope, Optimizations $optimizations)
 {
     $method = \cast($in, 'xp.compiler.ast.RoutineNode');
     // Search for return statement, then see if anything comes after it
     $s = sizeof($method->body);
     foreach ($method->body as $i => $statement) {
         if ($statement instanceof ReturnNode && $i < $s) {
             $method->body = array_slice($method->body, 0, $i + 1);
             // Include return
             break;
         }
     }
     return $method;
 }
开发者ID:xp-lang,项目名称:compiler,代码行数:22,代码来源:DeadCodeElimination.class.php

示例15: cast

 private static function cast($_inputs)
 {
     if (is_object($_inputs)) {
         if (class_exists($_inputs->getEqType_name())) {
             return cast($_inputs, $_inputs->getEqType_name());
         }
     }
     if (is_array($_inputs)) {
         $return = array();
         foreach ($_inputs as $input) {
             $return[] = self::cast($input);
         }
         return $return;
     }
     return $_inputs;
 }
开发者ID:saez0pub,项目名称:core,代码行数:16,代码来源:eqLogic.class.php


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