/usr/portage

NOWDOC + double quotes = HEREDOC 9

PHP 5.3 introduces a new syntax element, NOWDOC. If you know HEREDOC, NOWDOC is easy to understand: it is in fact HEREDOC taken literally. Whily variables are expanded in HEREDOC, in NOWDOC they are not. Just to remind us, a small HEREDOC example:

$value = "Hello World!";
$var = <<<LABEL
$value
LABEL;

$var will contain “Hello World!” now.

<?php
$value = "Hello World!";
$var = <<<'LABEL'
$value
LABEL;

$value is not expanded, so $var contains literally “$value”.

For consistency and the sake of completeness, an alternative syntax has been introduced:

<?php
$value = "Hello World!";
$var = <<<"LABEL"
$value
LABEL;

Guess how it behaves …

Filed on 12-04-2008, 18:06 under & nine comments & no trackbacks

Trackbacks

Trackback specific URI for this entry

No Trackbacks

Comments

  1. Richard Heyes says:
    published on April 12th 2008, 09:05:30 pm *

    Reply

  2. Lars Strojny returns:
    published on April 12th 2008, 09:31:20 pm *

    Reply

  3. Richard Heyes says:
    published on April 13th 2008, 01:05:54 pm *

    Reply

  4. Philip Olson opines:
    published on April 12th 2008, 11:01:40 pm *

    Reply

  5. Lars Strojny returns:
    published on April 14th 2008, 08:29:08 pm *

    Reply

  6. metapundit returns:
    published on April 15th 2008, 07:19:43 pm *

    Reply

  7. dave responses:
    published on April 16th 2008, 03:26:33 pm *

    Reply

  8. Jason Priebe means:
    published on August 4th 2009, 03:49:08 pm *

    Reply

  9. Lars Strojny opines:
    published on August 4th 2009, 03:59:45 pm *

    Reply

Add a Comment & let me know what you think