# [RFC] Alternative syntax for Nowdoc.

- Thread: https://externals.io/message/115213
- Original archive: https://news-web.php.net/php.internals/115213
- Started by Manuel Canga on 2021-06-29T16:15:19+00:00
- Messages: 14
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #115213 — Manuel Canga — 2021-06-29T16:15:19+00:00

URL: https://externals.io/message/115213#115213

Hi, folks, here again with a new purpose:  ``` as alternative to Nowdoc syntax.

Currently, Nowdoc syntax is very "verbose":

$string =<<<'CODE'
<div>
<p>Link: <a href="%s">'%s'</a><p>
</div>
CODE;

Why doesn't something like this?:

$string =```
<div>
<p>Link: <a href="%s">'%s'</a><p>
</div>
```;

even as well:

$string =```<div><p>Link: <a href="%s">'%s'</a><p></div>```;


I see a caveat: this is very similar to `eval` syntax. However, this syntax is more similar to Markdown syntax. 

What do you think ?

Regards
Manuel Canga

---

## #115214 — Rowan Tommins — 2021-06-29T16:40:05+00:00

URL: https://externals.io/message/115213#115214 · In reply to: #115213

> Hi, folks, here again with a new purpose:  ``` as alternative to Nowdoc syntax.
>
> Currently, Nowdoc syntax is very "verbose":
>
> $string =<<<'CODE'
> <div>
> <p>Link: <a href="%s">'%s'</a><p>
> </div>
> CODE;


The big advantage of heredoc and nowdoc syntax is that you can choose 
the delimiter to be something that you know won't occur in the string. 
For instance:

$markdown = <<<'MD'
PHP has lots of ways to write strings:
```
$example = 'hello';
$example = "hello";
$example = <<<EXAMPLE
hello
EXAMPLE;
$example = <<<EXAMPLE
hello
EXAMPLE;
```
MD;


Unless I'm missing something, your proposed syntax would just be a *more 
verbose* way of writing single quotes.


Regards,

-- 
Rowan Tommins
[IMSoP]

---

## #115215 — Manuel Canga — 2021-06-29T17:06:31+00:00

URL: https://externals.io/message/115213#115215 · In reply to: #115214

---- En mar, 29 jun 2021 18:40:05 +0200 Rowan Tommins <rowan.collins@gmail.com> escribió ----
 > 
 > The big advantage of heredoc and nowdoc syntax is that you can choose 
 > the delimiter to be something that you know won't occur in the string. 
 > For instance:
 > 
 > $markdown = <<<'MD'
 > PHP has lots of ways to write strings:
 > ```
 > $example = 'hello';
 > $example = "hello";
 > $example = <<<EXAMPLE
 > hello
 > EXAMPLE;
 > $example = <<<EXAMPLE
 > hello
 > EXAMPLE;
 > ```
 > MD;
 > 
 > 
 > Unless I'm missing something, your proposed syntax would just be a *more 
 > verbose* way of writing single quotes.
 
Hi, Rowan,

Basically, you're right. This would be a Heredoc variant of writing text without worrying about quotes (singles or doubles). Something like:

$quote =```"Sometimes it's better to leave something alone, to pause, and that's very true of programming." - Joyce Wheeler```;


Regards
Manuel Canga

---

## #115220 — michal.brzuchalski@gmail.com — 2021-06-29T19:33:19+00:00

URL: https://externals.io/message/115213#115220 · In reply to: #115213

Hi Manuel,

wt., 29 cze 2021 o 18:16 Manuel Canga <php@manuelcanga.dev> napisał(a):

> Hi, folks, here again with a new purpose:  ``` as alternative to Nowdoc
> syntax.
>
> Currently, Nowdoc syntax is very "verbose":
>
> $string =<<<'CODE'
> <div>
> <p>Link: <a href="%s">'%s'</a><p>
> </div>
> CODE;
>
> Why doesn't something like this?:
>
> $string =```
> <div>
> <p>Link: <a href="%s">'%s'</a><p>
> </div>
> ```;
>
> even as well:
>
> $string =```<div><p>Link: <a href="%s">'%s'</a><p></div>```;
>
>
> I see a caveat: this is very similar to `eval` syntax. However, this
> syntax is more similar to Markdown syntax.
>
> What do you think ?
>

I think a Markdown document including PHP code snippet with above examples
could cause issues while parsing.
I can imagine parsers don't expect end-of-snippet tag "```" being not an
end tag actually.

Cheers,
Michał Marcin Brzuchalski

---

## #115222 — Manuel Canga — 2021-06-29T22:57:41+00:00

URL: https://externals.io/message/115213#115222 · In reply to: #115220

---- En mar, 29 jun 2021 21:33:19 +0200 Michał Marcin Brzuchalski <michal.brzuchalski@gmail.com> escribió ----
 > Hi Manuel,
 > I think a Markdown document including PHP code snippet with above examples
 > could cause issues while parsing.
 > I can imagine parsers don't expect end-of-snippet tag "```" being not an
 > end tag actually.
 > 
 > Cheers,
 > Michał Marcin Brzuchalski
 

Hi, Michal,

You can escape backticks using a different number of backticks as a wrapper. Examples:

1.

``There is a literal backtick (`) here.``

We're using two backstick as wrapper of one backtick.

2. Using Rowan example:


````php
$markdown=```
PHP has lots of ways to write strings:  
```
$example = 'hello';  
$example = "hello";  
$example = <<<EXAMPLE  
hello  
EXAMPLE;  
$example = <<<EXAMPLE  
hello  
EXAMPLE;  
```
```
````

Live example: https://github.com/manuelcanga/RFC/blob/master/README.md

This works due to use four backticks as wrapper of three backticks.

Although these examples work generally, with some Markdown  parser can that  these doesn't work.

Maybe other syntax could be used, but I don't know which. In javascript only a backtick is used: https://developers.google.com/web/updates/2015/01/ES6-Template-Strings . But in PHP this is used as eval.


Regards,
Manuel Canga

---

## #115227 — Guilliam Xavier — 2021-06-30T09:03:32+00:00

URL: https://externals.io/message/115213#115227 · In reply to: #115222

Hi,

Maybe other syntax could be used, but I don't know which. In javascript
> only a backtick is used:
> https://developers.google.com/web/updates/2015/01/ES6-Template-Strings .
> But in PHP this is used as eval.
>

Just a precision, because you keep referring to it as "eval", which makes
me "tick" (haha): `$cmd` (i.e. $cmd wrapped in a pair of backticks) is the
same as shell_exec($cmd), not eval($cmd).

(BTW, one of JS "template strings" main selling points is string
substitution / variable interpolation, which is explicitly *not* wanted
with nowdoc [VS heredoc].)

As for the proposal, overall I agree with Rowan -- well, that would not be
exactly like single quotes (regarding [not] escaping them), but still "yet
another way" to write a nowdoc string literal.

PS: "amusingly", the code samples are hard to understand after rendered on
https://externals.io/message/115213

-- 
Guilliam Xavier

---

## #115228 — Lynn — 2021-06-30T09:16:24+00:00

URL: https://externals.io/message/115213#115228 · In reply to: #115227

On Wed, Jun 30, 2021 at 11:03 AM Guilliam Xavier <guilliam.xavier@gmail.com>
wrote:

> PS: "amusingly", the code samples are hard to understand after rendered on
> https://externals.io/message/115213


I'd expect a lot of markdown issues when trying to write examples using
backticks. While such a thing might not be blocking for a nice language
feature, it will surely impact the tooling in the ecosystem for
documentation. I already run into issues with single line code examples in
Discord because it gets messy real fast. Sure it's just an annoyance, but I
would like to suggest avoiding it if we can.
```
`const something = `foo`;`
```

---

## #115234 — Manuel Canga — 2021-06-30T10:51:56+00:00

URL: https://externals.io/message/115213#115234 · In reply to: #115227

---- En mié, 30 jun 2021 11:03:32 +0200 Guilliam Xavier <guilliam.xavier@gmail.com> escribió ----
 > Hi,

Hi Guilliam

 > Maybe other syntax could be used, but I don't know which. In javascript
> > […]
 > 
 > Just a precision, because you keep referring to it as "eval", which makes
 > me "tick" (haha): `$cmd` (i.e. $cmd wrapped in a pair of backticks) is the
 > same as shell_exec($cmd), not eval($cmd).

Yes, you're right. 
  
 > (BTW, one of JS "template strings" main selling points is string
 > substitution / variable interpolation, which is explicitly *not* wanted
 > with nowdoc [VS heredoc].)

Yes, I mean that in JS is used some similar (although as you say with variables).
I would prefer to use this "feature" with nowdoc. Normally, strings with variables are moved to views, while large literals (like queries) are added inline.
 
 > As for the proposal, overall I agree with Rowan -- well, that would not be
 > exactly like single quotes (regarding [not] escaping them), but still "yet
 > another way" to write a nowdoc string literal.

I see this purpose as a simplification of Nowdocs. Just like `[]` with `array()`.
  
 > PS: "amusingly", the code samples are hard to understand after rendered on
 > https://externals.io/message/115213

ups!, I'm sorry...but, look at:
https://externals.io/message/115213#115222
Markdown is not broken here due to ``` of code.

Regards,
Manuel Canga

---

## #115235 — Manuel Canga — 2021-06-30T11:06:57+00:00

URL: https://externals.io/message/115213#115235 · In reply to: #115228

---- En mié, 30 jun 2021 11:16:24 +0200 Lynn <kjarli@gmail.com> escribió ----
 > 
 > I'd expect a lot of markdown issues when trying to write examples using
 > backticks. While such a thing might not be blocking for a nice language
 > feature, it will surely impact the tooling in the ecosystem for
 > documentation. I already run into issues with single line code examples in
 > Discord because it gets messy real fast. Sure it's just an annoyance, but I
 > would like to suggest avoiding it if we can.
 > ```
 > `const something = `foo`;`
 > ```

Hi, Lynn. 

My intention wasn't a closed purpose. Maybe ``` is not a good syntax, In this case, other can be found.


Regards
Manuel Canga

---

## #115236 — Hamza Ahmad — 2021-06-30T11:11:59+00:00

URL: https://externals.io/message/115213#115236 · In reply to: #115234

Hi Manuel,

If I am not wrong, is not your proposal similar to python's
triple-quoted? It is confusing; don't do this. Instead, current syntax
are sufficient. Second, (`) have special meaning in PHP. It is used to
execute commands on a machine. Why do we have confusing syntax?

Best

Hamza Ahmad



>  ---- En mié, 30 jun 2021 11:03:32 +0200 Guilliam Xavier
> <guilliam.xavier@gmail.com> escribió ----
> > […]
>
> Hi Guilliam
>
> > […]
> .
> > […]
> makes
> > […]
> the
> > […]
>
> Yes, you're right.
>
> > […]
>
> Yes, I mean that in JS is used some similar (although as you say with
> variables).
> I would prefer to use this "feature" with nowdoc. Normally, strings with
> variables are moved to views, while large literals (like queries) are added
> inline.
>
> > […]
> be
> > […]
> "yet
> > […]
>
> I see this purpose as a simplification of Nowdocs. Just like `[]` with
> `array()`.
>
> > […]
> on
> > […]
>
> ups!, I'm sorry...but, look at:
> https://externals.io/message/115213#115222
> Markdown is not broken here due to ``` of code.
>
> Regards,
> Manuel Canga
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #115237 — Rowan Tommins — 2021-06-30T11:31:32+00:00

URL: https://externals.io/message/115213#115237 · In reply to: #115234

> I see this purpose as a simplification of Nowdocs. Just like `[]` with `array()`.


A PHP code base might have thousands of array literals, some of which 
will be very short, and maybe nested inside each other. That makes the 
saving of 5 characters per literal add up to a big difference across the 
code base.

On the other hand, nowdocs will generally be for long strings 
(otherwise, a single- or double-quoted string would be more concise 
anyway), and will happen a handful of times across the code base. Saving 
5 characters per nowdoc (``` instead of <<<'EOF') is therefore a much 
more minor difference.

In exchange for that small gain, we'd be adding an extra rule in every 
PHP parser (IDEs, code style tools, etc), and an extra thing for new 
developers to understand (the documentation for how to write strings is 
already long enough to get bored halfway through).

I think there is more cost than benefit.

Regards,

-- 
Rowan Tommins
[IMSoP]

---

## #115238 — G. P. B. — 2021-06-30T12:29:40+00:00

URL: https://externals.io/message/115213#115238 · In reply to: #115213

> Hi, folks, here again with a new purpose:  ``` as alternative to Nowdoc
> syntax.
>
> Currently, Nowdoc syntax is very "verbose":
>
> $string =<<<'CODE'
> <div>
> <p>Link: <a href="%s">'%s'</a><p>
> </div>
> CODE;
>
> Why doesn't something like this?:
>
> $string =```
> <div>
> <p>Link: <a href="%s">'%s'</a><p>
> </div>
> ```;
>
> even as well:
>
> $string =```<div><p>Link: <a href="%s">'%s'</a><p></div>```;
>
>
> I see a caveat: this is very similar to `eval` syntax. However, this
> syntax is more similar to Markdown syntax.
>
> What do you think ?
>
> Regards
> Manuel Canga
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>
I'm going to be harsh, but this proposal is utterly useless and harmful.
As already stated by other people this is just the same as single quotes,
and we frankly don't need yet another way of writing strings.
This doesn't even try to solve the issue with string interpolation that JS
does with backticks, which is an area in PHP which is quite a mess.

Now onto why this proposal is harmful:
This reuses syntax which has *very* different semantics (i.e. shell
execution) for something different,
moreso that the shell execution operator in PHP is valid markdown to go
into the same literal parsing mode as what the triple backtick do, just
inline.
Even if we deprecated the shell operator (RFC which got shutdown already) I
don't think it would be reasonable to reintroduce it without one full major
release cycle where it didn't have any effect/is a parse error.
This is also harmful for MarkDown because the whole point of the triple
backtick which kicks you into a literal parsing mode,
is so that you do not need to escape anything within this block, so your
suggestion to "just escape" goes against the very point of this syntax in
MarkDown,
which was probably chosen because it did not conflict with any programming
language whatsoever making it safe for this usage.

Ignoring the fact that this proposal is way past the cutoff date to be able
to make it into PHP 8.1 due to how the RFC process works,
it seems that this feature just came into your mind and you decided to send
it onto the list without considering its ramifications.
Userland contribution and opinions on new features (or other internal
discussion) is valuable but oughts to consider all the ramifications, good
and bad, and how it affects the language as a whole.
I say this because I didn't do this when I started contributing on this
list and it made for less than stellar discussions.
I would also recommend to any reader of this list who wants to propose a
new feature to do this at the start of a new release around September,
compared to moments before feature freeze where there are already a lot of
proposals flying around from many old-time core contributors.
The other benefit of doing this earlier than later is that you might even
be able to get someone to hand hold you to create a patch for the feature.

All this to say, this is a massive -1 from my end on this proposal.

Best regards,

George P. Banyard

---

## #115240 — Manuel Canga — 2021-06-30T13:20:13+00:00

URL: https://externals.io/message/115213#115240 · In reply to: #115238

---- En mié, 30 jun 2021 14:29:40 +0200 G. P. B. <george.banyard@gmail.com> escribió ----
 > Ignoring the fact that this proposal is way past the cutoff date to be able to make it into PHP 8.1 due to how the RFC process works,it seems that this feature just came into your mind and you decided to send it onto the list without considering its ramifications.Userland contribution and opinions on new features (or other internal discussion) is valuable but oughts to consider all the ramifications, good and bad, and how it affects the language as a whole. I say this because I didn't do this when I started contributing on this list and it made for less than stellar discussions.

Hi, George,

I am not an expert in developing programming languages. However, I don't agree with that.

When Dennis Ritchie and Brian Kernighan developed C. They didn't think in avoid pointers because of they thought what they could be dangerous.
Surely when someone invented air planes, he didn't think of risks but opportunities

It was my fault. I thought that someone here would propose an idea and if this was useful, then everyone would find the best way to put it into code.

With last Rowan email, I understood that this purpose is useless. However, if it had been useful, I had expected answers like:
"hey, Manuel, ``` is dangerous, why don't use other syntax like ...  ?
or
"Manuel,  why don't use this for heredoc ?

In one word: Synergy.

Why should this be done?. Because someone can read my purpose and can modify to something better, maybe a great change to the language.

I think so. 

Regards, 
Manuel Canga

---

## #115244 — Hamza Ahmad — 2021-06-30T14:21:10+00:00

URL: https://externals.io/message/115213#115244 · In reply to: #115240

Being positive is good but relying on others is not. If you really
believe that your idea is worth considering, I suggest revisiting it.
You can ask your self the following questions:
  - How is it useful?
  - what special thing does it provide with that the current
implementation does not?
  - What could be the better syntax?
  - Does any other language have the similar feature?
  - If yes, what is the benefit?
  - Will your idea cause any BC break?
  - Do your proposed syntax make any confusion?
  - How can you make it further clear?

If you have answers to all of these questions, you can come and
convince the people here. Still, I don't find your proposal till now
that compelling.

Rather considering the opinions shared here as an offence, take them
positively and redesign your thought.

Best

Hamza


>
>  ---- En mié, 30 jun 2021 14:29:40 +0200 G. P. B. <george.banyard@gmail.com>
> escribió ----
> > […]
> able to make it into PHP 8.1 due to how the RFC process works,it seems that
> this feature just came into your mind and you decided to send it onto the
> list without considering its ramifications.Userland contribution and
> opinions on new features (or other internal discussion) is valuable but
> oughts to consider all the ramifications, good and bad, and how it affects
> the language as a whole. I say this because I didn't do this when I started
> contributing on this list and it made for less than stellar discussions.
>
> Hi, George,
>
> I am not an expert in developing programming languages. However, I don't
> agree with that.
>
> When Dennis Ritchie and Brian Kernighan developed C. They didn't think in
> avoid pointers because of they thought what they could be dangerous.
> Surely when someone invented air planes, he didn't think of risks but
> opportunities
>
> It was my fault. I thought that someone here would propose an idea and if
> this was useful, then everyone would find the best way to put it into code.
>
> With last Rowan email, I understood that this purpose is useless. However,
> if it had been useful, I had expected answers like:
> "hey, Manuel, ``` is dangerous, why don't use other syntax like ...  ?
> or
> "Manuel,  why don't use this for heredoc ?
>
> In one word: Synergy.
>
> Why should this be done?. Because someone can read my purpose and can modify
> to something better, maybe a great change to the language.
>
> I think so.
>
> Regards,
> Manuel Canga
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php
