Ejemplo n.º 1
0
Variant f_constant(CStrRef name) {
  if (!name.get()) return uninit_null();
  const char *data = name.data();
  int len = name.length();
  char *colon;
  if ((colon = (char*)memchr(data, ':', len)) && colon[1] == ':') {
    // class constant
    int classNameLen = colon - data;
    char *constantName = colon + 2;
    VM::Class* cls = getClassByName(data, classNameLen);
    if (cls) {
      String cnsName(constantName, data + len - constantName, CopyString);
      TypedValue* tv = cls->clsCnsGet(cnsName.get());
      if (tv) {
        return tvAsCVarRef(tv);
      }
    }
    raise_warning("Couldn't find constant %s", data);
    return uninit_null();
  } else {
    TypedValue* cns = VM::Unit::loadCns(name.get());
    if (cns) return tvAsVariant(cns);
    return uninit_null();
  }
}
Ejemplo n.º 2
0
Variant f_constant(CStrRef name) {
  if (!name.get()) return null;
  const char *data = name.data();
  int len = name.length();
  char *colon;
  if ((colon = (char*)memchr(data, ':', len)) && colon[1] == ':') {
    // class constant
    int classNameLen = colon - data;
    char *constantName = colon + 2;
    String className(data, classNameLen, CopyString);

    // translate "self" or "parent"
    if (className == "self") {
      String this_class = g_vmContext->getContextClassName();
      if (this_class.empty()) {
        throw FatalErrorException("Cannot access self:: "
                                  "when no class scope is active");
      } else {
        className = this_class;
      }
    } else if (className == "parent") {
      String parent_class =g_vmContext->getParentContextClassName();
      if (parent_class.empty()) {
        throw FatalErrorException("Cannot access parent");
      } else {
        className = parent_class;
      }
    }
    VM::Class* cls = VM::Unit::loadClass(className.get());
    if (cls) {
      String cnsName(constantName, data + len - constantName, CopyString);
      TypedValue* tv = cls->clsCnsGet(cnsName.get());
      if (tv) {
        return tvAsCVarRef(tv);
      }
    }
    raise_warning("Couldn't find constant %s", data);
    return null;
  } else {
    TypedValue* cns = g_vmContext->getCns(name.get());
    if (cns == NULL) {
      if (AutoloadHandler::s_instance->autoloadConstant(name)) {
        cns = g_vmContext->getCns(name.get());
      }
    }
    if (cns) return tvAsVariant(cns);
    return null;
  }
}
Ejemplo n.º 3
0
bool f_defined(CStrRef name, bool autoload /* = true */) {
  if (!name.get()) return false;
  const char *data = name.data();
  int len = name.length();
  char *colon;
  if ((colon = (char*)memchr(data, ':', len)) && colon[1] == ':') {
    // class constant
    int classNameLen = colon - data;
    char *constantName = colon + 2;
    VM::Class* cls = getClassByName(data, classNameLen);
    if (cls) {
      String cnsName(constantName, data + len - constantName, CopyString);
      return cls->clsCnsGet(cnsName.get());
    }
    return false;
  } else {
    return autoload ?
      VM::Unit::loadCns(name.get()) :
      VM::Unit::lookupCns(name.get());
  }
}