fixup.test 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. Fixup for precedence and some special syntax
  2. -----
  3. <?php
  4. $a ** $b * $c;
  5. $a + $b * $c;
  6. $a * $b + $c;
  7. $a ? $b : $c;
  8. ($a ** $b) * $c;
  9. ( $a ** $b ) * $c;
  10. !$a = $b;
  11. -----
  12. // Parens necessary
  13. $stmts[0]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b'));
  14. // The parens here are "correct", because add is left assoc
  15. $stmts[1]->expr->right = new Expr\BinaryOp\Plus(new Expr\Variable('b'), new Expr\Variable('c'));
  16. // No parens necessary
  17. $stmts[2]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b'));
  18. // Parens for RHS not strictly necessary due to assign speciality
  19. $stmts[3]->expr->cond = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b'));
  20. $stmts[3]->expr->if = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b'));
  21. $stmts[3]->expr->else = new Expr\Assign(new Expr\Variable('a'), new Expr\Variable('b'));
  22. // Already has parens
  23. $stmts[4]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b'));
  24. $stmts[5]->expr->left = new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b'));
  25. -----
  26. <?php
  27. ($a + $b) * $c;
  28. $a + ($b + $c);
  29. $a + $b + $c;
  30. ($a = $b) ? $a = $b : ($a = $b);
  31. ($a + $b) * $c;
  32. ( $a + $b ) * $c;
  33. !$a = $b;
  34. -----
  35. <?php
  36. foo ();
  37. foo ();
  38. $foo -> bar;
  39. $foo -> bar;
  40. $foo -> bar;
  41. $foo -> bar;
  42. $foo -> bar;
  43. self :: $foo;
  44. self :: $foo;
  45. -----
  46. $stmts[0]->expr->name = new Expr\Variable('a');
  47. $stmts[1]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
  48. $stmts[2]->expr->var = new Expr\Variable('bar');
  49. $stmts[3]->expr->var = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
  50. $stmts[4]->expr->name = new Node\Identifier('foo');
  51. // In this case the braces are not strictly necessary. However, on PHP 5 they may be required
  52. // depending on where the property fetch node itself occurs.
  53. $stmts[5]->expr->name = new Expr\Variable('bar');
  54. $stmts[6]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
  55. $stmts[7]->expr->name = new Node\VarLikeIdentifier('bar');
  56. $stmts[8]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b'));
  57. -----
  58. <?php
  59. $a ();
  60. ($a . $b) ();
  61. $bar -> bar;
  62. ($a . $b) -> bar;
  63. $foo -> foo;
  64. $foo -> {$bar};
  65. $foo -> {$a . $b};
  66. self :: $bar;
  67. self :: ${$a . $b};