diff --git a/src/parser/xhpast/api/XHPASTNode.php b/src/parser/xhpast/api/XHPASTNode.php --- a/src/parser/xhpast/api/XHPASTNode.php +++ b/src/parser/xhpast/api/XHPASTNode.php @@ -3,16 +3,10 @@ final class XHPASTNode extends AASTNode { public function isStaticScalar() { - switch ($this->getTypeName()) { - case 'n_NUMERIC_SCALAR': - return true; - - case 'n_STRING_SCALAR': - return $this->checkIsConstantString(array('n_MAGIC_SCALAR')); - - default: - return false; - } + return in_array($this->getTypeName(), array( + 'n_STRING_SCALAR', + 'n_NUMERIC_SCALAR', + )); } public function getDocblockToken() { @@ -39,12 +33,6 @@ return $this->getChildByIndex(0)->evalStatic(); break; case 'n_STRING_SCALAR': - if (!$this->checkIsConstantString()) { - throw new Exception( - pht( - 'Non-constant scalar strings cannot be statically evaluated.')); - } - return (string)$this->getStringLiteralValue(); case 'n_NUMERIC_SCALAR': $value = $this->getSemanticString(); diff --git a/src/parser/xhpast/api/__tests__/XHPASTTreeTestCase.php b/src/parser/xhpast/api/__tests__/XHPASTTreeTestCase.php --- a/src/parser/xhpast/api/__tests__/XHPASTTreeTestCase.php +++ b/src/parser/xhpast/api/__tests__/XHPASTTreeTestCase.php @@ -55,6 +55,9 @@ $this->assertEval(0, '0'); + // Static evaluation treats '$' as a literal dollar glyph. + $this->assertEval('$asdf', '"$asdf"'); + $this->assertEval( '\a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z'. '\1\2\3\4\5\6\7\8\9\0'.