fix constant()

we don't store constants with the preceeding ##\## so slice it off. I originally edited ##name## but couldn't find a clean c++-ish way to do that. I'm open to teachings.
Esse commit está contido em:
Paul Tarjan
2013-05-09 11:46:20 -07:00
commit de Sara Golemon
commit 61c545c838
6 arquivos alterados com 56 adições e 6 exclusões
@@ -862,6 +862,7 @@ ExpressionPtr SimpleFunctionCall::preOptimize(AnalysisResultConstPtr ar) {
return CONSTANT("true");
}
ConstantTableConstPtr constants = ar->getConstants();
if (symbol[0] == '\\') symbol = symbol.substr(1);
// system constant
if (constants->isPresent(symbol) && !constants->isDynamic(symbol)) {
return CONSTANT("true");
+34 -6
Ver Arquivo
@@ -93,6 +93,15 @@ Variant f_constant(CStrRef name) {
if (!name.get()) return uninit_null();
const char *data = name.data();
int len = name.length();
// slice off starting backslash
bool hadInitialBackslash = false;
if (len > 0 && data[0] == '\\') {
data += 1;
len -= 1;
hadInitialBackslash = true;
}
char *colon;
if ((colon = (char*)memchr(data, ':', len)) && colon[1] == ':') {
// class constant
@@ -107,12 +116,18 @@ Variant f_constant(CStrRef name) {
}
}
raise_warning("Couldn't find constant %s", data);
return uninit_null();
} else {
TypedValue* cns = Unit::loadCns(name.get());
TypedValue* cns;
if (hadInitialBackslash) {
String s(data, len, CopyString);
cns = VM::Unit::loadCns(s.get());
} else {
cns = VM::Unit::loadCns(name.get());
}
if (cns) return tvAsVariant(cns);
return uninit_null();
}
return uninit_null();
}
bool f_define(CStrRef name, CVarRef value,
@@ -127,6 +142,15 @@ bool f_defined(CStrRef name, bool autoload /* = true */) {
if (!name.get()) return false;
const char *data = name.data();
int len = name.length();
// slice off starting backslash
bool hadInitialBackslash = false;
if (len > 0 && data[0] == '\\') {
data += 1;
len -= 1;
hadInitialBackslash = true;
}
char *colon;
if ((colon = (char*)memchr(data, ':', len)) && colon[1] == ':') {
// class constant
@@ -139,9 +163,13 @@ bool f_defined(CStrRef name, bool autoload /* = true */) {
}
return false;
} else {
return autoload ?
Unit::loadCns(name.get()) :
Unit::lookupCns(name.get());
auto* cb = autoload ? VM::Unit::loadCns : VM::Unit::lookupCns;
if (hadInitialBackslash) {
String s(data, len, CopyString);
return cb(s.get());
} else {
return cb(name.get());
}
}
}
+14
Ver Arquivo
@@ -0,0 +1,14 @@
<?php
error_reporting(-1);
define('\B', 1);
var_dump(B);
const B = 1;
var_dump(B);
var_dump(constant('B'));
var_dump(constant('\B'));
var_dump(defined('B'));
var_dump(defined('\B'));
@@ -0,0 +1,7 @@
HipHop Notice: Use of undefined constant B - assumed 'B' in %s on line 5
string(1) "B"
int(1)
int(1)
int(1)
bool(true)
bool(true)