php.runtime.Memory.isArray()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(104)

本文整理了Java中php.runtime.Memory.isArray()方法的一些代码示例,展示了Memory.isArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Memory.isArray()方法的具体详情如下:
包路径:php.runtime.Memory
类名称:Memory
方法名:isArray

Memory.isArray介绍

暂无

代码示例

代码示例来源:origin: jphp-group/jphp

public static Memory valueForList(Memory memory, long index) {
  if (memory.isArray()) {
    return memory.valueOfIndex(index);
  } else {
    return Memory.NULL;
  }
}

代码示例来源:origin: jphp-group/jphp

public static Memory valueForList(Memory memory, Memory index) {
  if (memory.isArray()) {
    return memory.valueOfIndex(index);
  } else {
    return Memory.NULL;
  }
}

代码示例来源:origin: jphp-group/jphp

public static Memory valueForList(Memory memory, String index) {
  if (memory.isArray()) {
    return memory.valueOfIndex(index);
  } else {
    return Memory.NULL;
  }
}

代码示例来源:origin: jphp-group/jphp

@Override
public boolean isArray() {
  return getValue().isArray();
}

代码示例来源:origin: jphp-group/jphp

public static boolean is_array(@Reference Memory memory) {
  return memory.isArray();
}

代码示例来源:origin: jphp-group/jphp

public boolean isTraversable() { return isArray() || instanceOf("Traversable", "traversable"); }
public boolean isString() { return type == Type.STRING; }

代码示例来源:origin: jphp-group/jphp

@Signature
public String set(String key, Memory value) {
  String s = value.toString();
  if (value.isArray()) {
    s = StringUtils.join(value.toValue(ArrayMemory.class).toStringArray(), "|");
  }
  Object property = properties.setProperty(key, s);
  return property == null ? null : property.toString();
}

代码示例来源:origin: jphp-group/jphp

public static Memory vsprintf(Environment env, TraceInfo trace, String format, Memory array) {
  if (array.isArray()) {
    return sprintf(env, trace, format, array.toValue(ArrayMemory.class).values());
  } else
    return sprintf(env, trace, format, array);
}

代码示例来源:origin: jphp-group/jphp

public static int vprintf(Environment env, TraceInfo trace, String format, Memory array) {
  if (array.isArray()) {
    return printf(env, trace, format, array.toValue(ArrayMemory.class).values());
  } else
    return printf(env, trace, format, array);
}

代码示例来源:origin: jphp-group/jphp

public SplClassLoader(Invoker invoker, Memory callback){
  this.invoker = invoker;
  this.callback = callback;
  if (invoker instanceof StaticMethodInvoker && !callback.isArray()){
    StaticMethodInvoker staticMethodInvoker = (StaticMethodInvoker)invoker;
    this.callback = ArrayMemory.ofStrings(
        staticMethodInvoker.getCalledClass(),
        staticMethodInvoker.getMethod().getName()
    );
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature(@Arg(value = "args", type = HintType.ARRAY, optional = @Optional(type = HintType.ARRAY)))
public Memory newInstanceArgs(Environment env, Memory... args) throws Throwable {
  if (args[0].isArray()) {
    return newInstance(env, args[0].toValue(ArrayMemory.class).values(true));
  } else
    return Memory.NULL;
}

代码示例来源:origin: jphp-group/jphp

private static int recursive_count(Environment env, TraceInfo trace, ArrayMemory array, Set<Integer> used){
  ForeachIterator iterator = array.foreachIterator(false, false);
  int size = array.size();
  while (iterator.next()){
    Memory el = iterator.getValue();
    if (el.isArray()){
      if (used == null)
        used = new HashSet<>();
      int pointer = el.getPointer();
      if (!used.add(pointer)){
        env.warning(trace, "recursion detected");
      } else {
        size += recursive_count(env, trace, array, used);
      }
      used.remove(pointer);
    }
  }
  return size;
}

代码示例来源:origin: jphp-group/jphp

public void unsetArguments(Memory[] arguments){
  if (arguments != null){
    int x = 0;
    for(Memory argument : arguments) {
      if (argument == null) continue;
      if (argument.isArray()) {
        ParameterEntity param = parameters != null && x < parameters.length ? parameters[x] : null;
        if (param == null || (param.isUsed() && param.isMutable() && !param.isReference())) {
          argument.unset();
        }
      }
      x++;
    }
  }
}

代码示例来源:origin: jphp-group/jphp

@Immutable
public static Memory strlen(Environment env, TraceInfo trace, Memory string) {
  if (string.isArray()) {
    env.warning(trace, "expects parameter 1 to be string, array given");
    return Memory.NULL;
  }
  if (string instanceof BinaryMemory)
    return LongMemory.valueOf(string.getBinaryBytes(env.getDefaultCharset()).length);
  return LongMemory.valueOf(string.toString().length());
}

代码示例来源:origin: jphp-group/jphp

@Immutable
public static Memory max(Memory value, Memory... args){
  if (value.isArray() && args == null){
    Memory max = null;
    for (Memory one : (ArrayMemory)value){
      if (max == null || one.greater(max))
        max = one;
    }
    return max == null ? Memory.NULL : max.toImmutable();
  } else {
    Memory max = value;
    if (args != null)
      for(Memory one : args){
        if (one.greater(max))
          max = one;
      }
    return max.toImmutable();
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature({
    @Arg("name"), @Arg("value"),
    @Arg(value = "caseSensitive", optional = @Optional(value = "true", type = HintType.BOOLEAN))
})
public Memory defineConstant(Environment env, Memory... args){
  Memory val = args[1].toValue();
  if (val.isArray() || val.isObject())
    env.exception("Argument 2 must be a scalar value");
  if (!environment.defineConstant(args[0].toString(), val, args[2].toBoolean()))
    env.exception("Constant '%s' already registered", args[0]);
  return Memory.NULL;
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testArrayReturn() {
  Memory memory = runDynamic("$baseDir = 'foobar_'; return array(" +
      "    'a' => $baseDir . 'bla',);", false);
  Assert.assertTrue(memory.isArray());
  Assert.assertEquals("foobar_bla", memory.valueOfIndex("a").toString());
  Assert.assertEquals(1, memory.toValue(ArrayMemory.class).size());
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testProperties() throws Throwable {
  Memory memory;
  memory = runDynamic("class A { var $x = 11, $y = 30; } return new A();", false);
  Assert.assertTrue(memory.isObject());
  IObject object = ((ObjectMemory)memory).value;
  Assert.assertEquals(11, object.getReflection().getProperty(environment, null, object, "x", null, 0).toLong());
  Assert.assertEquals(30, object.getReflection().getProperty(environment, null, object, "y", null, 0).toLong());
  memory = runDynamic("class A { public $arr = array(1, 2, 3); } return new A()->arr;", false);
  Assert.assertTrue(memory.isArray());
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testClassicDefine(){
  Memory memory = includeResource("arrays/classic_define.php");
  Assert.assertTrue(memory.isArray());
  ArrayMemory array = memory.toValue(ArrayMemory.class);
  Assert.assertEquals(3, array.size());
  Assert.assertEquals(1, array.valueOfIndex(0).toLong());
  Assert.assertEquals(2, array.valueOfIndex(1).toLong());
  Assert.assertEquals(3, array.valueOfIndex(2).toLong());
}

代码示例来源:origin: jphp-group/jphp

@Test
public void testShortDefine(){
  Memory memory = includeResource("arrays/short_define.php");
  Assert.assertTrue(memory.isArray());
  ArrayMemory array = memory.toValue(ArrayMemory.class);
  Assert.assertEquals(3, array.size());
  Assert.assertEquals(1, array.valueOfIndex(0).toLong());
  Assert.assertEquals(2, array.valueOfIndex(1).toLong());
  Assert.assertEquals(3, array.valueOfIndex(2).toLong());
}

相关文章