From a9c9d5f2ad488a2bdbf225dc13f4ed0b8e745add Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Thu, 21 Feb 2008 19:50:29 +0000 Subject: [PATCH] added documentation for nowdocs git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@253479 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/types/string.xml | 116 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 5 deletions(-) diff --git a/language/types/string.xml b/language/types/string.xml index e9c9c34131..5e2100898b 100644 --- a/language/types/string.xml +++ b/language/types/string.xml @@ -1,5 +1,5 @@ - + Strings @@ -23,7 +23,7 @@ Syntax - A string literal can be specified in three different ways: + A string literal can be specified in four different ways: @@ -42,6 +42,12 @@ heredoc syntax + + + nowdoc syntax + (since PHP 5.3) + + @@ -222,8 +228,8 @@ echo 'Variables do not $expand $either'; - Heredocs can not be used for initializing class members. Use other - string syntaxes instead. + Heredocs can not be used for initializing class members. Use + nowdocs instead. @@ -286,7 +292,13 @@ EOT; ]]> - + &example.outputs; + + + Heredoc support was added in PHP 4. @@ -294,6 +306,100 @@ EOT; + + + Nowdoc + + + Nowdocs are to single-quoted strings what heredocs are to double-quoted + strings. A nowdoc is specified similarly to a heredoc, but no + parsing is done inside a nowdoc. The construct is ideal for + embedding PHP code or other large blocks of text without the need for + escaping. It shares some features in common with the SGML + &lt;![CDATA[ ]]&gt; construct, in that it declares a + block of text which is not for parsing. + + + + A nowdoc is identified with the same <<< + seqeuence used for heredocs, but the identifier which follows is enclosed in + single quotes, e.g. <<<'EOT'. All the rules for + heredoc identifiers also apply to nowdoc identifiers, especially those + regarding the appearance of the closing identifier. + + + + Nowdoc string quoting example + +foo = 'Foo'; + $this->bar = array('Bar1', 'Bar2', 'Bar3'); + } +} + +$foo = new foo(); +$name = 'MyName'; + +echo <<<'EOT' +My name is "$name". I am printing some $foo->foo. +Now, I am printing some {$foo->bar[1]}. +This should not print a capital 'A': \x41 +EOT; +?> +]]> + + + &example.outputs; + +foo. +Now, I am printing some {$foo->bar[1]}. +This should not print a capital 'A': \x41]]> + + + + Unlike heredocs, nowdocs can be used in any static data context. The + typical example is initializing class members or constants: + + + + Static data example + + +]]> + + + + + + + Nowdoc support was added in PHP 5.3. + + + + Variable parsing