From 432aeb74d5a49e6f0efd1063113cef099c93aef6 Mon Sep 17 00:00:00 2001 From: murphy Date: Mon, 28 Dec 2009 07:27:12 +0000 Subject: Copying changes and fixes for 0.9.0rc3 from terminal-encoder branch over to trunk. --- test/scanners/php/strings.expected.raydebug | 360 ++++++++++++++++++++++++++++ 1 file changed, 360 insertions(+) create mode 100644 test/scanners/php/strings.expected.raydebug (limited to 'test/scanners/php/strings.expected.raydebug') diff --git a/test/scanners/php/strings.expected.raydebug b/test/scanners/php/strings.expected.raydebug new file mode 100644 index 0000000..c8e3e84 --- /dev/null +++ b/test/scanners/php/strings.expected.raydebug @@ -0,0 +1,360 @@ +plain(Single quoted +)inline_delimiter(operator(;) + +predefined(echo) stringoperator(;) + +comment(// Outputs: Arnold once said: "I'll be back") +predefined(echo) stringoperator(;) + +comment(// Outputs: You deleted C:\\*.*?) +predefined(echo) stringoperator(;) + +comment(// Outputs: You deleted C:\\*.*?) +predefined(echo) stringoperator(;) + +comment(// Outputs: This will not expand: \\n a newline) +predefined(echo) stringoperator(;) + +comment(// Outputs: Variables do not $expand $either) +predefined(echo) stringoperator(;) +inline_delimiter(?>) + +plain(Double quoted + +)inline_delimiter(operator(;) +inline_delimiter(?>) + +plain(Heredoc + +Example #1 Invalid example +)inline_delimiter(operator(;) +operator(}) +inline_delimiter(?>) + +plain(Example #2 Heredoc string quoting example + +)inline_delimiter(operator(;) + +comment(/* More complex example, with variables. */) +reserved(class) class(foo) +operator({) + reserved(var) local_variable($foo)operator(;) + reserved(var) local_variable($bar)operator(;) + + reserved(function) function(foo)operator(()operator(\)) + operator({) + local_variable($this)operator(->)ident(foo) operator(=) stringoperator(;) + local_variable($this)operator(->)ident(bar) operator(=) predefined(array)operator(()stringoperator(,) stringoperator(,) stringoperator(\))operator(;) + operator(}) +operator(}) + +local_variable($foo) operator(=) reserved(new) ident(foo)operator(()operator(\))operator(;) +local_variable($name) operator(=) stringoperator(;) + +predefined(echo) string)ident(foo)>content(.)content( +)content(Now, I am printing some )inline)ident(bar)operator([)integer(1)operator(])delimiter(})>content(.)content( +)content(This should print a capital 'A': )char(\\x41)content( +)delimiter(EOT)>operator(;) +inline_delimiter(?>) + +plain(The above example will output: + +My name is "MyName". I am printing some Foo. +Now, I am printing some Bar2. +This should print a capital 'A': A + +Example #3 Heredoc in arguments example + +)inline_delimiter( +operator(\))operator(\))operator(;) +inline_delimiter(?>) + +plain(Example #4 Using Heredoc to initialize static values + +)inline_delimiter(operator(;) +operator(}) + +comment(// Class properties/constants) +reserved(class) class(foo) +operator({) + reserved(const) constant(BAR) operator(=) stringoperator(;) + + reserved(public) local_variable($baz) operator(=) stringoperator(;) +operator(}) +inline_delimiter(?>) + +plain(Example #5 Using double quotes in Heredoc + +)inline_delimiter(operator(;) +inline_delimiter(?>) + +plain(Nowdoc + +Example #6 Nowdoc string quoting example + +)inline_delimiter(operator(;) + +comment(/* More complex example, with variables. */) +reserved(class) class(foo) +operator({) + reserved(public) local_variable($foo)operator(;) + reserved(public) local_variable($bar)operator(;) + + reserved(function) function(foo)operator(()operator(\)) + operator({) + local_variable($this)operator(->)ident(foo) operator(=) stringoperator(;) + local_variable($this)operator(->)ident(bar) operator(=) predefined(array)operator(()stringoperator(,) stringoperator(,) stringoperator(\))operator(;) + operator(}) +operator(}) + +local_variable($foo) operator(=) reserved(new) ident(foo)operator(()operator(\))operator(;) +local_variable($name) operator(=) stringoperator(;) + +predefined(echo) stringfoo.)content( +)content(Now, I am printing some {$foo->bar[1]}.)content( +)content(This should not print a capital 'A': )content(\\x)content(41)content( +)delimiter(EOT)>operator(;) +inline_delimiter(?>) +plain(The above example will output: + +My name is "$name". I am printing some $foo-)error(>)plain(foo. +Now, I am printing some {$foo-)error(>)plain(bar[1]}. +This should not print a capital 'A': \\x41 + +Example #7 Static data example + +)inline_delimiter(operator(;) +operator(}) +inline_delimiter(?>) + +plain(Variable parsing + +When a string is specified in double quotes or with heredoc, variables are parsed within it. + +There are two types of syntax: a simple one and a complex one. The simple syntax is the most common and convenient. It provides a way to embed a variable, an array value, or an object property in a string with a minimum of effort. + +The complex syntax was introduced in PHP 4, and can be recognised by the curly braces surrounding the expression. + +Simple syntax + +If a dollar sign ($\) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name. + +)inline_delimiter(operator(;) +predefined(echo) stringoperator(;) comment(// works; "'" is an invalid character for variable names) +predefined(echo) stringoperator(;) comment(// won't work; 's' is a valid character for variable names but the variable is "$beer") +predefined(echo) stringoperator(;) comment(// works) +predefined(echo) stringcontent(s)delimiter(")>operator(;) comment(// works) +inline_delimiter(?>) +plain(Similarly, an array index or an object property can be parsed. With array indices, the closing square bracket (]\) marks the end of the index. The same rules apply to object properties as to simple variables. + +)inline_delimiter( operator(=>) stringoperator(,) string operator(=>) stringoperator(\))operator(;) + +comment(// Works, but note that this works differently outside a string) +predefined(echo) stringcontent(.)delimiter(")>operator(;) + +comment(// Works) +predefined(echo) stringoperator(])delimiter(})>content(.)delimiter(")>operator(;) + +comment(// Works, but PHP looks for a constant named banana first, as described below.) +predefined(echo) stringcontent(.)delimiter(")>operator(;) + +comment(// Won't work, use braces. This results in a parse error.) +predefined(echo) stringoperator(;) + +comment(// Works) +predefined(echo) string operator(.) local_variable($fruits)operator([)stringoperator(]) operator(.) stringoperator(;) + +comment(// Works) +predefined(echo) string)ident(width)>content( meters broad.)delimiter(")>operator(;) + +comment(// Won't work. For a solution, see the complex syntax.) +predefined(echo) string)ident(width00)>content( centimeters broad.)delimiter(")>operator(;) +inline_delimiter(?>) +plain(For anything more complex, you should use the complex syntax. + +Complex (curly\) syntax + +This isn't called complex because the syntax is complex, but because it allows for the use of complex expressions. + +In fact, any value in the namespace can be included in a string with this syntax. Simply write the expression the same way as it would appear outside the string, and then wrap it in { and }. Since { can not be escaped, this syntax will only be recognised when the $ immediately follows the {. Use {\\$ to get a literal {$. Some examples to make it clear: + +)inline_delimiter(operator(;) + +comment(// Won't work, outputs: This is { fantastic}) +predefined(echo) stringoperator(;) + +comment(// Works, outputs: This is fantastic) +predefined(echo) stringdelimiter(")>operator(;) +predefined(echo) stringoperator(;) + +comment(// Works) +predefined(echo) string)ident(width)delimiter(})>content(00 centimeters broad.)delimiter(")>operator(;) + +comment(// Works) +predefined(echo) stringdelimiter(")>operator(;) + +comment(// This is wrong for the same reason as $foo[bar] is wrong outside a string.) +comment(// In other words, it will still work, but only because PHP first looks for a) +comment(// constant named foo; an error of level E_NOTICE (undefined constant\) will be) +comment(// thrown.) +predefined(echo) stringdelimiter(")>operator(;) + +comment(// Works. When using multi-dimensional arrays, always use braces around arrays) +comment(// when inside of strings) +predefined(echo) stringoperator(])operator([)integer(3)operator(])delimiter(})>delimiter(")>operator(;) + +comment(// Works.) +predefined(echo) string operator(.) local_variable($arr)operator([)stringoperator(])operator([)integer(3)operator(])operator(;) + +predefined(echo) string)ident(values)operator([)integer(3)operator(])operator(->)ident(name)delimiter(})>delimiter(")>operator(;) + +predefined(echo) stringdelimiter(")>operator(;) + +predefined(echo) stringdelimiter(")>operator(;) + +predefined(echo) stringgetName(\): )inline)ident(getName)operator(()operator(\))operator(})delimiter(})>delimiter(")>operator(;) +inline_delimiter(?>) +plain(It is also possible to access class properties using variables within strings using this syntax. + +)inline_delimiter(operator(;) +operator(}) + +local_variable($foo) operator(=) reserved(new) ident(foo)operator(()operator(\))operator(;) +local_variable($bar) operator(=) stringoperator(;) +local_variable($baz) operator(=) predefined(array)operator(()stringoperator(,) stringoperator(,) stringoperator(,) stringoperator(\))operator(;) +predefined(echo) string)local_variable($bar)delimiter(})>char(\\n)delimiter(")>operator(;) +predefined(echo) string)local_variable($baz)operator([)integer(1)operator(])delimiter(})>char(\\n)delimiter(")>operator(;) +inline_delimiter(?>) +plain(The above example will output: +I am bar. +I am bar. + +Note: Functions, method calls, static class variables, and class constants inside {$} work since PHP 5. However, the value accessed will be interpreted as the name of a variable in the scope in which the string is defined. Using single curly braces ({}\) will not work for accessing the return values of functions or methods or the values of class constants or static class variables. +)inline_delimiter(operator(;) + reserved(public) reserved(static) local_variable($ale) operator(=) stringoperator(;) +operator(}) + +local_variable($rootbeer) operator(=) stringoperator(;) +local_variable($ipa) operator(=) stringoperator(;) + +comment(// This works; outputs: I'd like an A & W) +predefined(echo) stringchar(\\n)delimiter(")>operator(;) + +comment(// This works too; outputs: I'd like an Alexander Keith's) +predefined(echo) stringchar(\\n)delimiter(")>operator(;) +inline_delimiter(?>) +plain(String access and modification by character + +Characters within strings may be accessed and modified by specifying the zero-based offset of the desired character after the string using square array brackets, as in $str[42]. Think of a string as an array of characters for this purpose. + +Note: Strings may also be accessed using braces, as in $str{42}, for the same purpose. However, this syntax is deprecated as of PHP 5.3.0. Use square brackets instead, such as $str[42]. + +Warning +Writing to an out of range offset pads the string with spaces. Non-integer types are converted to integer. Illegal offset type emits E_NOTICE. Negative offset emits E_NOTICE in write but reads empty string. Only the first character of an assigned string is used. Assigning empty string assigns NUL byte. + +Example #8 Some string examples +)inline_delimiter(operator(;) +local_variable($first) operator(=) local_variable($str)operator([)integer(0)operator(])operator(;) + +comment(// Get the third character of a string) +local_variable($third) operator(=) local_variable($str)operator([)integer(2)operator(])operator(;) + +comment(// Get the last character of a string.) +local_variable($str) operator(=) stringoperator(;) +local_variable($last) operator(=) local_variable($str)operator([)predefined(strlen)operator(()local_variable($str)operator(\))operator(-)integer(1)operator(])operator(;) + +comment(// Modify the last character of a string) +local_variable($str) operator(=) stringoperator(;) +local_variable($str)operator([)predefined(strlen)operator(()local_variable($str)operator(\))operator(-)integer(1)operator(]) operator(=) stringoperator(;) + +inline_delimiter(?>) + +plain(String conversion to numbers + +)inline_delimiter(operator(;) comment(// $foo is float (11.5\)) +local_variable($foo) operator(=) integer(1) operator(+) stringoperator(;) comment(// $foo is float (-1299\)) +local_variable($foo) operator(=) integer(1) operator(+) stringoperator(;) comment(// $foo is integer (1\)) +local_variable($foo) operator(=) integer(1) operator(+) stringoperator(;) comment(// $foo is integer (1\)) +local_variable($foo) operator(=) integer(1) operator(+) stringoperator(;) comment(// $foo is integer (11\)) +local_variable($foo) operator(=) integer(4) operator(+) stringoperator(;) comment(// $foo is float (14.2\)) +local_variable($foo) operator(=) string operator(+) integer(1)operator(;) comment(// $foo is float (11\)) +local_variable($foo) operator(=) string operator(+) float(1.0)operator(;) comment(// $foo is float (11\) ) +inline_delimiter(?>) + +inline_delimiter( operator(.) predefined(gettype) operator(()local_variable($foo)operator(\)) operator(.) string)char(\\n)delimiter(")>operator(;) +inline_delimiter(?>) + +plain(If you want a parsed variable surrounded by curly braces, just double the curly braces: + +)inline_delimiter(operator(;) + predefined(echo) stringcontent(})delimiter(")>operator(;) +inline_delimiter(?>) + +plain(Although current documentation says 'A string literal can be specified in four different ways: ...', actually there is a fifth way to specify a (binary\) string: + +)inline_delimiter(operator(;) inline_delimiter(?>) -- cgit v1.2.1