diff --git a/bin/systemlib.php b/bin/systemlib.php index 91519efea..f2d777c23 100644 --- a/bin/systemlib.php +++ b/bin/systemlib.php @@ -5135,6 +5135,51 @@ class ReflectionClass implements Reflector { public function getAttributesRecursive() { return $this->fetch('attributes_rec'); } + +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://www.php.net/manual/en/reflectionclass.innamespace.php ) + * + * Checks if in namespace + * + * @return bool Returns TRUE on success or FALSE on failure. + */ + public function inNamespace() { + return strrpos($this->getName(), '\\') !== false; + } + +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://php.net/manual/en/reflectionclass.getnamespacename.php ) + * + * Gets namespace name + * + * @return string The namespace name. + */ + public function getNamespaceName() { + $pos = strrpos($this->getName(), '\\'); + if ($pos === false) { + return ''; + } + return substr($this->getName(), 0, $pos); + } + +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://www.php.net/manual/en/reflectionclass.getshortname.php ) + * + * Gets short name + * + * @return string The class short name. + */ + public function getShortName() { + $pos = strrpos($this->getName(), '\\'); + if ($pos === false) { + return $this->getName(); + } + return substr($this->getName(), $pos + 1); + } + } /////////////////////////////////////////////////////////////////////////////// diff --git a/hphp/compiler/analysis/analysis_result.cpp b/hphp/compiler/analysis/analysis_result.cpp index d5571ea6a..a8e91bba4 100644 --- a/hphp/compiler/analysis/analysis_result.cpp +++ b/hphp/compiler/analysis/analysis_result.cpp @@ -14,12 +14,13 @@ +----------------------------------------------------------------------+ */ +#include "hphp/compiler/analysis/analysis_result.h" + #include #include #include #include #include -#include "hphp/compiler/analysis/analysis_result.h" #include "hphp/compiler/analysis/alias_manager.h" #include "hphp/compiler/analysis/file_scope.h" #include "hphp/compiler/analysis/class_scope.h" @@ -169,7 +170,7 @@ FunctionScopePtr AnalysisResult::findFunction( const std::string &funcName) const { StringToFunctionScopePtrMap::const_iterator bit = m_functions.find(funcName); - if (bit != m_functions.end() && !bit->second->ignoreRedefinition()) { + if (bit != m_functions.end() && !bit->second->allowOverride()) { return bit->second; } StringToFunctionScopePtrMap::const_iterator iter = @@ -345,7 +346,7 @@ bool AnalysisResult::declareFunction(FunctionScopePtr funcScope) const { // System functions override auto it = m_functions.find(fname); if (it != m_functions.end()) { - if (!it->second->ignoreRedefinition()) { + if (!it->second->allowOverride()) { // we need someone to hold on to a reference to it // even though we're not going to do anything with it this->lock()->m_ignoredScopes.push_back(funcScope); diff --git a/hphp/compiler/analysis/emitter.cpp b/hphp/compiler/analysis/emitter.cpp index ff967b871..5ea4a63f5 100644 --- a/hphp/compiler/analysis/emitter.cpp +++ b/hphp/compiler/analysis/emitter.cpp @@ -5873,7 +5873,7 @@ bool EmitterVisitor::canEmitBuiltinCall(FunctionCallPtr fn, return false; } // in sandbox mode, don't emit FCallBuiltin for redefinable functions - if (func->ignoreRedefinition() && !Option::WholeProgram) { + if (func->allowOverride() && !Option::WholeProgram) { return false; } return true; diff --git a/hphp/compiler/analysis/file_scope.h b/hphp/compiler/analysis/file_scope.h index 7532fe032..e5341dfba 100644 --- a/hphp/compiler/analysis/file_scope.h +++ b/hphp/compiler/analysis/file_scope.h @@ -59,7 +59,7 @@ public: MixedVariableArgument = 0x800, // variable args, may or may not be ref'd IsFoldable = 0x1000,// function can be constant folded NeedsActRec = 0x2000,// builtin function needs ActRec - IgnoreRedefinition = 0x4000,// ignore redefinition of builtin function + AllowOverride = 0x4000,// allow override of systemlib or builtin }; typedef boost::adjacency_list Graph; diff --git a/hphp/compiler/analysis/function_scope.cpp b/hphp/compiler/analysis/function_scope.cpp index 4e2dbbc08..f1fd6754c 100644 --- a/hphp/compiler/analysis/function_scope.cpp +++ b/hphp/compiler/analysis/function_scope.cpp @@ -302,8 +302,8 @@ bool FunctionScope::isVariableArgument() const { return res; } -bool FunctionScope::ignoreRedefinition() const { - return m_attribute & FileScope::IgnoreRedefinition; +bool FunctionScope::allowOverride() const { + return m_attribute & FileScope::AllowOverride; } bool FunctionScope::isReferenceVariableArgument() const { @@ -378,8 +378,8 @@ void FunctionScope::setVariableArgument(int reference) { } } -void FunctionScope::setIgnoreRedefinition() { - m_attribute |= FileScope::IgnoreRedefinition; +void FunctionScope::setAllowOverride() { + m_attribute |= FileScope::AllowOverride; } bool FunctionScope::hasEffect() const { diff --git a/hphp/compiler/analysis/function_scope.h b/hphp/compiler/analysis/function_scope.h index f4bc2746d..f401a3a83 100644 --- a/hphp/compiler/analysis/function_scope.h +++ b/hphp/compiler/analysis/function_scope.h @@ -222,10 +222,10 @@ public: void setNeedsActRec(); /* - * If this is a builtin and can be redefined + * If this is a builtin (C++ or PHP) and can be redefined */ - bool ignoreRedefinition() const; - void setIgnoreRedefinition(); + bool allowOverride() const; + void setAllowOverride(); /** * Whether this function is a runtime helper function diff --git a/hphp/compiler/builtin_symbols.cpp b/hphp/compiler/builtin_symbols.cpp index c8917cf1c..cee047bd6 100644 --- a/hphp/compiler/builtin_symbols.cpp +++ b/hphp/compiler/builtin_symbols.cpp @@ -203,8 +203,8 @@ FunctionScopePtr BuiltinSymbols::ImportFunctionScopePtr(AnalysisResultPtr ar, if (attrs & ClassInfo::NeedsActRec) { f->setNeedsActRec(); } - if ((attrs & ClassInfo::IgnoreRedefinition) && !isMethod) { - f->setIgnoreRedefinition(); + if ((attrs & ClassInfo::AllowOverride) && !isMethod) { + f->setAllowOverride(); } FunctionScope::RecordFunctionInfo(f->getName(), f); diff --git a/hphp/idl/base.php b/hphp/idl/base.php index b519af937..6232b283c 100644 --- a/hphp/idl/base.php +++ b/hphp/idl/base.php @@ -121,7 +121,7 @@ define('IsFinal', 1 << 5); define('IsPublic', 1 << 6); define('IsProtected', 1 << 7); define('IsPrivate', 1 << 8); -define('IgnoreRedefinition', 1 << 8); +define('AllowOverride', 1 << 8); define('IsStatic', 1 << 9); // FIXME (#2163116): IsInherited = (1 << 10) in base_class.h define('IsCppAbstract', 1 << 10); @@ -162,7 +162,7 @@ function get_flag_names($arr, $name, $global_func) { if ($flag & IsPublic ) $ret .= ' | IsPublic' ; if ($flag & IsProtected ) $ret .= ' | IsProtected' ; if ($global_func) { - if ($flag & IgnoreRedefinition ) $ret .= ' | IgnoreRedefinition' ; + if ($flag & AllowOverride ) $ret .= ' | AllowOverride' ; } else { if ($flag & IsPrivate ) $ret .= ' | IsPrivate' ; } diff --git a/hphp/runtime/base/class_info.h b/hphp/runtime/base/class_info.h index 953b1f861..88195f717 100644 --- a/hphp/runtime/base/class_info.h +++ b/hphp/runtime/base/class_info.h @@ -52,7 +52,7 @@ public: IsInherited = (1 << 10), // x HasCall = IsPublic, // x HasCallStatic = IsProtected,// x - IgnoreRedefinition = IsPrivate, // x + AllowOverride = IsPrivate, // x IsReference = (1 << 11), // x x x IsConstructor = (1 << 12), // x diff --git a/hphp/runtime/vm/func.cpp b/hphp/runtime/vm/func.cpp index ef125e3fe..ac7ca3794 100644 --- a/hphp/runtime/vm/func.cpp +++ b/hphp/runtime/vm/func.cpp @@ -654,6 +654,11 @@ void Func::setCached() { setCachedFunc(this, isDebuggerAttached()); } +bool Func::isAllowOverride() const { + return shared()->m_info && + (shared()->m_info->attribute & ClassInfo::AllowOverride); +} + const Func* Func::getGeneratorBody(const StringData* name) const { if (isNonClosureMethod()) { return cls()->lookupMethod(name); diff --git a/hphp/runtime/vm/func.h b/hphp/runtime/vm/func.h index adf682bfb..2601b0691 100644 --- a/hphp/runtime/vm/func.h +++ b/hphp/runtime/vm/func.h @@ -347,10 +347,7 @@ struct Func { bool hasStaticLocals() const { return !shared()->m_staticVars.empty(); } int numStaticLocals() const { return shared()->m_staticVars.size(); } const ClassInfo::MethodInfo* info() const { return shared()->m_info; } - bool isIgnoreRedefinition() const { - return shared()->m_info && - (shared()->m_info->attribute & ClassInfo::IgnoreRedefinition); - } + bool isAllowOverride() const; const BuiltinFunction& nativeFuncPtr() const { return shared()->m_nativeFuncPtr; } diff --git a/hphp/runtime/vm/func_inline.h b/hphp/runtime/vm/func_inline.h index 22b66735b..eebc37ae3 100644 --- a/hphp/runtime/vm/func_inline.h +++ b/hphp/runtime/vm/func_inline.h @@ -29,7 +29,7 @@ inline ALWAYS_INLINE void setCachedFunc(Func* func, bool debugger) { Func** funcAddr = getCachedFuncAddr(func->getCachedOffset()); if (UNLIKELY(*funcAddr != nullptr)) { if (*funcAddr == func) return; - if (!(*funcAddr)->isIgnoreRedefinition()) { + if (!(*funcAddr)->isAllowOverride()) { raise_error(Strings::FUNCTION_ALREADY_DEFINED, func->name()->data()); } } diff --git a/hphp/runtime/vm/funcdict.cpp b/hphp/runtime/vm/funcdict.cpp index 4f973b525..9a430314c 100644 --- a/hphp/runtime/vm/funcdict.cpp +++ b/hphp/runtime/vm/funcdict.cpp @@ -14,12 +14,13 @@ +----------------------------------------------------------------------+ */ +#include "hphp/runtime/vm/funcdict.h" + #include "hphp/runtime/base/runtime_option.h" #include "hphp/util/base.h" #include "hphp/runtime/base/execution_context.h" #include "hphp/runtime/ext_hhvm/ext_hhvm.h" -#include "hphp/runtime/vm/funcdict.h" #include "hphp/runtime/vm/translator/translator.h" #include "hphp/runtime/vm/translator/targetcache.h" #include "hphp/runtime/vm/unit.h" @@ -57,7 +58,7 @@ bool RenamedFuncDict::rename(const StringData* old, const StringData* n3w) { if (fnew && fnew != func) { // To match hphpc, we silently ignore functions defined in user code that // have the same name as a function defined in a separable extension - if (!fnew->isIgnoreRedefinition()) { + if (!fnew->isAllowOverride()) { raise_error("Function already defined: %s", n3w->data()); } else { return false;