/* * Helper method from converting between a PHP function and a CufIter. */ bool vm_decode_function_cufiter(const Variant& function, CufIterPtr& cufIter) { ObjectData* obj = nullptr; Class* cls = nullptr; StringData* invName = nullptr; // Don't warn here, let the caller decide what to do if the func is nullptr. const HPHP::Func* func = vm_decode_function(function, GetCallerFrame(), false, obj, cls, invName, DecodeFlags::NoWarn); if (func == nullptr) { return false; } cufIter = req::make_unique<CufIter>(); cufIter->setFunc(func); cufIter->setName(invName); if (obj) { cufIter->setCtx(obj); obj->incRefCount(); } else { cufIter->setCtx(cls); } return true; }
static bool modify_extract_name(VarEnv* v, String& name, int64_t extract_type, const String& prefix) { switch (extract_type) { case EXTR_SKIP: if (v->lookup(name.get()) != nullptr) { return false; } break; case EXTR_IF_EXISTS: if (v->lookup(name.get()) == nullptr) { return false; } else { goto namechecks; } break; case EXTR_PREFIX_SAME: if (v->lookup(name.get()) != nullptr) { name = prefix + "_" + name; } else { goto namechecks; } break; case EXTR_PREFIX_ALL: name = prefix + "_" + name; break; case EXTR_PREFIX_INVALID: if (!is_valid_var_name(name.get()->data(), name.size())) { name = prefix + "_" + name; } else { goto namechecks; } break; case EXTR_PREFIX_IF_EXISTS: if (v->lookup(name.get()) == nullptr) { return false; } name = prefix + "_" + name; break; case EXTR_OVERWRITE: namechecks: if (name == s_GLOBALS) { return false; } if (name == s_this) { // Only disallow $this when inside a non-static method, or a static method // that has defined $this (matches Zend) auto const func = arGetContextFunc(GetCallerFrame()); if (func && func->isMethod() && v->lookup(s_this.get()) != nullptr) { return false; } } default: break; } // skip invalid variable names, as in PHP return is_valid_var_name(name.get()->data(), name.size()); }