* Test the PHP Parser with different PHP snippets
*/
public void testPHPParser() {
+ checkPHP("function foo()" +\r "{" +\r " echo \"In foo()<br>\\n\";" +\r "}" +\r "" +\r "function bar($arg = '')" +\r "{" +\r " echo \"In bar(); argument was '$arg'.<br>\\n\";" +\r "}" +\r "" +\r "// This is a wrapper function around echo" +\r "function echoit($string)" +\r "{" +\r " echo $string;" +\r "}" +\r "" +\r "$func = 'foo';" +\r "$func(); // This calls foo()" +\r "" +\r "$func = 'bar';" +\r "$func('test'); // This calls bar()" +\r "" +\r "$func = 'echoit';" +\r "$func('test'); // This calls echoit()" +\r "");
+ checkPHP("class Foo" +\r "{" +\r " function Vari()" +\r " {" +\r " $name = 'Bar';" +\r " $this->$name(); // This calls the Bar() method\n" +\r " }" +\r " " +\r " function Bar()" +\r " {" +\r " echo \"This is Bar\";" +\r " }" +\r "}" +\r "" +\r "$foo = new Foo();" +\r "$funcname = \"Var\";" +\r "$foo->$varname(); // This calls $foo->Var()\n" +\r "");
+ checkPHP("function square ($num)" +\r "{" +\r " return $num * $num;" +\r "}" +\r "echo square (4); // outputs '16'." +\r "");
+ checkPHP("function small_numbers()" +\r "{" +\r " return array (0, 1, 2);" +\r "}" +\r "list ($zero, $one, $two) = small_numbers();" +\r "");
+ checkPHP("function &returns_reference()" +\r "{" +\r " return $someref;" +\r "}" +\r "" +\r "$newref =& returns_reference();" +\r " " +\r "");
+ checkPHP("function add_some_extra(&$string)" +\r "{" +\r " $string .= 'and something extra.';" +\r "}" +\r "$str = 'This is a string, ';" +\r "add_some_extra($str);" +\r "echo $str; ");
+ checkPHP("function makecoffee ($type = \"cappuccino\")\n" +\r "{\n" +\r " return \"Making a cup of $type.\\n\";\n" +\r "}" +\r "echo makecoffee ();" +\r "echo makecoffee (\"espresso\");" +\r "");
+ checkPHP("$makefoo = true;" +\r "" +\r "/* We can't call foo() from here " +\r " since it doesn't exist yet," +\r " but we can call bar() */" +\r "" +\r "bar();" +\r "" +\r "if ($makefoo) {" +\r " function foo ()" +\r " {" +\r " echo \"I don't exist until program execution reaches me.\\n\";" +\r " }" +\r "}" +\r "" +\r "/* Now we can safely call foo()" +\r " since $makefoo evaluated to true */" +\r "" +\r "if ($makefoo) foo();" +\r "" +\r "function bar() " +\r "{" +\r " echo \"I exist immediately upon program start.\\n\";" +\r "}" +\r "" +\r "");
+ checkPHP(
+ "function foo() " +\r "{" +\r " function bar() " +\r " {" +\r " echo \"I don't exist until foo() is called.\\n\";" +\r " }" +\r "}" +\r "" +\r "/* We can't call bar() yet" +\r " since it doesn't exist. */" +\r "" +\r "foo();\n" +\r "" +\r "/* Now we can call bar()," +\r " foo()'s processesing has" +\r " made it accessable. */" +\r "" +\r "bar();" +\r "");
// Bugs item #690938
checkPHP(
" echo \"This is a test\"; // This is a one-line c++ style comment\n"