diff --git a/hphp/compiler/analysis/emitter.cpp b/hphp/compiler/analysis/emitter.cpp index f6652e4e7..0c1a17ba8 100644 --- a/hphp/compiler/analysis/emitter.cpp +++ b/hphp/compiler/analysis/emitter.cpp @@ -5241,10 +5241,17 @@ void EmitterVisitor::emitPostponedMeths() { initScalar(dv, vNode); pi.setDefaultValue(dv); - // Simple case: it's a scalar value so we just serialize it - VariableSerializer vs(VariableSerializer::PHPOutput); - String result = vs.serialize(tvAsCVarRef(&dv), true); - phpCode = StringData::GetStaticString(result.data()); + std::string orig = vNode->getComment(); + if (orig.empty()) { + // Simple case: it's a scalar value so we just serialize it + VariableSerializer vs(VariableSerializer::PHPOutput); + String result = vs.serialize(tvAsCVarRef(&dv), true); + phpCode = StringData::GetStaticString(result.get()); + } else { + // This was optimized from a Constant, or ClassConstant + // use the original string + phpCode = StringData::GetStaticString(orig); + } } else { // Non-scalar, so we have to output PHP from the AST node std::ostringstream os; diff --git a/hphp/compiler/expression/constant_expression.h b/hphp/compiler/expression/constant_expression.h index 4f3fe0c11..c44e8432c 100644 --- a/hphp/compiler/expression/constant_expression.h +++ b/hphp/compiler/expression/constant_expression.h @@ -61,7 +61,7 @@ public: void pushConst(const std::string &name); void popConst(); void setComment(const std::string &comment) { m_comment = comment;} - const std::string getComment() { return m_comment;} + std::string getComment() { return m_comment;} bool isValid() const { return m_valid; } bool isDynamic() const { return m_dynamic; } private: diff --git a/hphp/compiler/expression/expression.h b/hphp/compiler/expression/expression.h index a23562f6c..4cbac592e 100644 --- a/hphp/compiler/expression/expression.h +++ b/hphp/compiler/expression/expression.h @@ -172,6 +172,7 @@ public: } bool hasSubExpr(ExpressionPtr sub) const; virtual void setComment(const std::string &) {} + virtual std::string getComment() { return ""; } /** * Set this expression's error flags. */ diff --git a/hphp/compiler/expression/scalar_expression.h b/hphp/compiler/expression/scalar_expression.h index d7eb90c58..e0f527db3 100644 --- a/hphp/compiler/expression/scalar_expression.h +++ b/hphp/compiler/expression/scalar_expression.h @@ -70,7 +70,7 @@ public: int64_t getHash() const; void setComment(const std::string &comment) { m_comment = comment;} - const std::string getComment() { return m_comment;} + std::string getComment() { return m_comment;} bool getString(const std::string *&s) const;