Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use tokens to determine implicitness

  • Loading branch information...
commit f5311b30e94265f76fe3b3d42b6905ccfce4b315 1 parent 88913ab
@scoates scoates authored committed
Showing with 14 additions and 6 deletions.
  1. +14 −6 PHP/Repl.php
View
20 PHP/Repl.php
@@ -207,10 +207,10 @@ private function read()
*/
private function cleanup($input)
{
- static $implicit = array('return', 'throw', 'class', 'function',
- 'interface', 'abstract', 'static', 'echo',
- 'include', 'include_once', 'require',
- 'require_once');
+ static $implicit = array(T_RETURN, T_THROW, T_CLASS, T_FUNCTION,
+ T_INTERFACE, T_ABSTRACT, T_STATIC, T_ECHO,
+ T_INCLUDE, T_INCLUDE_ONCE, T_REQUIRE,
+ T_REQUIRE_ONCE, T_TRY, ';');
static $sugar = array(',' => 'dissect',
'd' => 'doc',
'l' => 'dir',
@@ -259,10 +259,18 @@ private function cleanup($input)
++$semicount;
$input .= ';';
}
+ // grab the "first" token's value
+ if (isset($tokens[1])) {
+ if (is_array($tokens[1])) {
+ $first = $tokens[1][0];
+ } else {
+ $first = $tokens[1];
+ }
+ } else {
+ $first = null;
+ }
// Make sure we get a value back from eval()
- // but if input contains a semi-colon
- $first = substr($input, 0, strpos($input, " "));
if (!in_array($first, $implicit) && (1 === $semicount)) {
$input = 'return ' . $input;
}
Please sign in to comment.
Something went wrong with that request. Please try again.