Exemple #1
0
Array vm_get_class_constants(CStrRef className) {
  HPHP::VM::Class* cls = HPHP::VM::Unit::lookupClass(className.get());
  if (cls == NULL) {
    return NEW(HphpArray)(0);
  }

  size_t numConstants = cls->numConstants();
  HphpArray* retVal = NEW(HphpArray)(numConstants);
  const VM::Class::Const* consts = cls->constants();
  for (size_t i = 0; i < numConstants; i++) {
    // Note: hphpc doesn't include inherited constants in
    // get_class_constants(), so mimic that behavior
    if (consts[i].m_class == cls) {
      StringData* name  = const_cast<StringData*>(consts[i].m_name);
      TypedValue* value = cls->clsCnsGet(consts[i].m_name);
      retVal->nvSet(name, value, false);
    }
  }

  return retVal;
}
Exemple #2
0
bool eval_get_class_constant_hook(Variant &res, CStrRef s,
                                  const char* constant) {
  if (hhvm) {
    String clsName(s, strlen(s), CopyString);
    HPHP::VM::Class* cls = HPHP::VM::Unit::lookupClass(clsName.get());
    if (cls && !cls->clsInfo()) {
      String cnsName(constant, strlen(constant), CopyString);
      TypedValue* tv = cls->clsCnsGet(cnsName.get());
      if (tv) {
        res = tvAsCVarRef(tv);
        return true;
      }
    }
  } else {
    const Eval::ClassStatement* cls =
      Eval::RequestEvalState::findClass(s, true);
    if (cls) {
      return cls->getConstant(res, constant, true);
    }
  }
  return false;
}