Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Disable `constant()` from the runtime
Summary: Add options to disable the constant method.
Reviewed By: kmeht
Differential Revision: D10112355
fbshipit-source-id: f7fd7d6726822939e59f240bf942e7ef6eafa5fd
- Loading branch information
|
@@ -434,6 +434,7 @@ uint64_t RuntimeOption::UndefinedConstFallback = 0; |
|
|
uint64_t RuntimeOption::DisableAssert = 0; |
|
|
bool RuntimeOption::DisallowExecutionOperator = false; |
|
|
bool RuntimeOption::DisableVariableVariables = false; |
|
|
uint64_t RuntimeOption::DisableConstant = 0; |
|
|
|
|
|
#ifdef HHVM_DYNAMIC_EXTENSION_DIR |
|
|
std::string RuntimeOption::ExtensionDir = HHVM_DYNAMIC_EXTENSION_DIR; |
|
@@ -1226,14 +1227,17 @@ void RuntimeOption::Load( |
|
|
"Hack.Lang.Phpism.DisallowExecutionOperator", |
|
|
DisallowExecutionOperator); |
|
|
Config::Bind(DisableVariableVariables, ini, config, |
|
|
"Hack.Lang.Phpism.DisableVariableVariables", |
|
|
DisableVariableVariables); |
|
|
"Hack.Lang.Phpism.DisableVariableVariables", |
|
|
DisableVariableVariables); |
|
|
Config::Bind(DisableDefine, ini, config, |
|
|
"Hack.Lang.Phpism.DisableDefine", |
|
|
DisableDefine); |
|
|
Config::Bind(DisableAssert, ini, config, |
|
|
"Hack.Lang.Phpism.DisableAssert", |
|
|
DisableAssert); |
|
|
Config::Bind(DisableConstant, ini, config, |
|
|
"Hack.Lang.Phpism.DisableConstant", |
|
|
DisableConstant); |
|
|
} |
|
|
{ |
|
|
// Repo |
|
|
|
@@ -519,6 +519,10 @@ struct RuntimeOption { |
|
|
// Disables PHP's variable variables |
|
|
// true => error, false => allows use of variable variables |
|
|
static bool DisableVariableVariables; |
|
|
// Disables PHP's constant function |
|
|
// valid values are 0 => enabled (default) |
|
|
// 1 => warning, 2 => error |
|
|
static uint64_t DisableConstant; |
|
|
// Disables PHP's define() function |
|
|
// valid values are 0 => enabled (default) |
|
|
// 1 => warning, 2 => error |
|
|
|
@@ -393,6 +393,13 @@ static Class* getClassByName(const char* name, int len) { |
|
|
} |
|
|
|
|
|
Variant HHVM_FUNCTION(constant, const String& name) { |
|
|
auto const warning = "constant() is deprecated and subject" |
|
|
" to removal from the Hack language"; |
|
|
switch (RuntimeOption::DisableConstant) { |
|
|
case 0: break; |
|
|
case 1: raise_warning(warning); break; |
|
|
default: raise_error(warning); |
|
|
} |
|
|
if (!name.get()) return init_null(); |
|
|
const char *data = name.data(); |
|
|
int len = name.length(); |
|
|
|
|
@@ -0,0 +1,4 @@ |
|
|
<?hh |
|
|
|
|
|
const HELLO = 123; |
|
|
echo(constant('HELLO')); |
|
|
@@ -0,0 +1,3 @@ |
|
|
|
|
|
Warning: constant() is deprecated and subject to removal from the Hack language in %s on line %d |
|
|
123 |
|
|
@@ -0,0 +1 @@ |
|
|
-vRuntime.Hack.Lang.Phpism.DisableConstant=1 |
|
|
@@ -0,0 +1 @@ |
|
|
-vHack.Lang.Phpism.DisableConstant=1 |
|
|
@@ -0,0 +1,4 @@ |
|
|
<?hh |
|
|
|
|
|
const HELLO = 123; |
|
|
echo(constant('HELLO')); |
|
|
@@ -0,0 +1,2 @@ |
|
|
|
|
|
Fatal error: constant() is deprecated and subject to removal from the Hack language in %s on line %d |
|
|
@@ -0,0 +1 @@ |
|
|
-vRuntime.Hack.Lang.Phpism.DisableConstant=2 |
|
|
@@ -0,0 +1 @@ |
|
|
-vHack.Lang.Phpism.DisableConstant=2 |