Skip to content

Commit e636614

Browse files
committed
Add special PHP functions like echo or exit
1 parent 44886af commit e636614

File tree

8 files changed

+25
-21
lines changed

8 files changed

+25
-21
lines changed

examples/assignation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
foo = "biz";
2+
bar = foo;
3+
4+
echo(bar);

examples/assignation.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$foo = "biz";
2+
$bar = $foo;
3+
echo($bar);

src/JsPhpize/Compiler/Compiler.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,32 @@ protected function visitFunctionCall(FunctionCall $functionCall, $indent)
183183
$function = $functionCall->function;
184184
$arguments = $functionCall->arguments;
185185
$arguments = $this->visitNodesArray($arguments, $indent, ', ');
186-
$call = 'call_user_func(' .
186+
$dynamicCall = 'call_user_func(' .
187187
$this->visitNode($function, $indent) .
188188
($arguments === '' ? '' : ', ' . $arguments) .
189189
')';
190190

191191
if ($function instanceof Variable) {
192192
$name = $function->name;
193+
$staticCall = $name . '(' . $arguments . ')';
194+
195+
if (in_array($name, array(
196+
'array',
197+
'echo',
198+
'print',
199+
'printf',
200+
'exit',
201+
))) {
202+
return $staticCall;
203+
}
204+
193205

194206
return 'function_exists(' . var_export($name, true) . ') ? ' .
195-
$name . '(' . $arguments . ') : ' .
196-
$call;
207+
$staticCall . ' : ' .
208+
$dynamicCall;
197209
}
198210

199-
return $call;
211+
return $dynamicCall;
200212
}
201213

202214
protected function visitHooksArray(HooksArray $array, $indent)

src/JsPhpize/Nodes/Assignable.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@
55
interface Assignable
66
{
77
public function getNonAssignableReason();
8-
9-
public function isAssignable();
108
}

src/JsPhpize/Nodes/Assignation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class Assignation extends Value
2323

2424
public function __construct($operator, Assignable $leftHand, Node $rightHand)
2525
{
26-
if (!$leftHand->isAssignable()) {
27-
throw new Exception($leftHand->getNonAssignableReason(), 9);
26+
if ($reason = $leftHand->getNonAssignableReason()) {
27+
throw new Exception($reason, 9);
2828
}
2929

3030
$this->operator = $operator;

src/JsPhpize/Nodes/Constant.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,4 @@ public function getNonAssignableReason()
3737
return "'M_' prefix is reserved to mathematical constants.";
3838
}
3939
}
40-
41-
public function isAssignable()
42-
{
43-
return !$this->getNonAssignableReason();
44-
}
4540
}

src/JsPhpize/Nodes/Variable.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,4 @@ public function setScope(Block $block)
3333
public function getNonAssignableReason()
3434
{
3535
}
36-
37-
public function isAssignable()
38-
{
39-
return true;
40-
}
4136
}

src/JsPhpize/Parser/Parser.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,6 @@ protected function getInitialValue($token)
377377
protected function appendFunctionsCalls(&$value)
378378
{
379379
while ($token = $this->get(0)) {
380-
if ($token->isValue()) {
381-
$this->unexpected($this->next());
382-
}
383380
if ($token->is('{') || $token->expectNoLeftMember()) {
384381
$this->unexpected($this->next());
385382
}

0 commit comments

Comments
 (0)