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 …
Comments
Show comments linear or threaded
Richard Heyes answers:
published on 2008|04|12, 21:05hSo it’s comparable to single vs double quotes wrt variable expansion?
BTW, your colours aren’t very good (from a low visibility point of view). In fact I’d go as far to say that they’re awful.
Lars Strojny states:
published on 2008|04|12, 21:31hExactly. The consistency argument applies because of double/single-quotes notation in variable assignments.
Colors: you mean the syntax highlighting or the colors in general? If you refer to the syntax highlighting, this must be improved in fact. The rest seems to be fine, even for color blind people.
Richard Heyes responses:
published on 2008|04|13, 13:05h> Colors: you mean the syntax highlighting or the
> colors in general? If you refer to the syntax
> highlighting, this must be improved in fact. The
> rest seems to be fine, even for color blind people.
The colours in general. Speaking as someone with shit sight (I believe that’s a technical term), they aren’t. Not enough contrast by far. And this text area which is the same colour as your background – what’s the story with that? Are you trying to disguise it? :-)
If you’re interested I wrote an paper on low visibility guidlines (which actually turned into general tips on improving usability for disabled users) here: http://www.phpguru.org/article.php/128
At the very least I would advise providing a different stylesheet.
Philip Olson opines:
published on 2008|04|12, 23:01hGreat new feature, thanks Gwynne for NOWDOC and thanks Lars for introducing the double quoted version.
Next on the agenda, remove the requirement of forcing LABEL; to be flush left… ;-)
Lars Strojny replies:
published on 2008|04|14, 20:29hAllowing the label to be in an abitrary location seems not to hard. What advantage would that have for you?
metapundit replies:
published on 2008|04|15, 19:19hHear hear!
It’s a tiny irritation, but the way the terminator works messes up auto-indenting and code folding features in my editor (by breaking the indentation levels). Even aside from my editor it’s just a visual irritant not to be able to indent code consistently.
I’d also like to allow whitespace after the terminating label – I sometimes get an “unexpected end of file on line xxx” error that I stare at for a minute before realizing that a single (invisible) space after the semicolon is messing me up.
dave supposes:
published on 2008|04|16, 15:26h1. Thanks for your post about NOWDOC!
2. I agree totally with Philip (and others) about the syntax of HEREDOC and NOWDOC. There should be more freedom in how the LABEL terminator is aligned (as well as use of spaces, etc.) with prior coding. Thanks.
3. I’m also recently sight impaired and some additional contrast on your website would be helpful.
—
Thank you again for this information.
>>>Dave
Add comment