# Nowdocs revised

- Thread: https://externals.io/message/31183
- Original archive: https://news-web.php.net/php.internals/31183
- Started by Gwynne Raskind on 2007-07-23T13:21:40+00:00
- Messages: 10
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #31183 — Gwynne Raskind — 2007-07-23T13:21:40+00:00

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

I've taken my original nowdocs patch and revamped it to be much more  
efficient and functional. This version:

- Parses nowdocs as constant strings rather than ADD_STRING opcodes.
- Allows the flex scanner do less work.
- Enables nowdocs to be used in static_scalar contexts, such as class  
constants and static variable initializers.
- Includes more tests than before.
- Is fully compatible with the most recent CVS checkouts for HEAD and  
PHP_5_2, and also merges cleanly into a 5.2.3 source tree.
- Breaks zero regression tests out of all 3000 or so.

The patch also cleans up the zend_language_scanner.l code a little  
bit, cosmetically speaking, and the PHP_5_2 patch updates the scanner  
by factoring out single-quoted string scanning, as HEAD already did.  
The patch is available for download at <http:// 
phpdoc.gwynne.dyndns.org/nowdocs.zip>, and browsable at <http:// 
phpdoc.gwynne.dyndns.org/nowdocs/>.

-- Gwynne, Daughter of the Code
"This whole world is an asylum for the incurable."

---

## #31604 — Gwynne Raskind — 2007-08-16T00:05:04+00:00

URL: https://externals.io/message/31183#31604

> Did you get any further with merging this?  It would help users of
> the XQuery language.
>
> If I understand your intent, I would be able to change the code  
> fragment
> below to use a nowdoc, and not have to escape the XQuery $i variables.
>
> Chris
>
>
> <?php
>
> $c = oci_connect("hr", "hrpwd", "localhost/orcl");
>
> $xq = <<<END
> select column_value
> from xmltable('for \$i in ora:view("locations") return \$i')
> END;
>
> $s = oci_parse($c, $xq);
> oci_execute($s);
> while ($row = oci_fetch_row($s))
> 	var_dump($row);
> ?>

I didn't get any further, no :(. The decision of whether to merge the  
nowdocs patch is out of my hands now, since I don't have source  
karma. However, since the main thing standing in the way of its  
implementation was concern over the usefulness, your comment is very  
helpful, and I'd like to open the topic for discussion again on the  
list, if no one out there has any objection :)

-- Gwynne, Daughter of the Code
"This whole world is an asylum for the incurable."

---

## #31619 — Richard Quadling — 2007-08-16T08:22:23+00:00

URL: https://externals.io/message/31183#31619 · In reply to: #31604

> 
> > […]
>
> I didn't get any further, no :(. The decision of whether to merge the
> nowdocs patch is out of my hands now, since I don't have source
> karma. However, since the main thing standing in the way of its
> implementation was concern over the usefulness, your comment is very
> helpful, and I'd like to open the topic for discussion again on the
> list, if no one out there has any objection :)

Being able to code templates within PHP rather than as an external
file without any escaping or variable expansion _is_ useful.


-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

---

## #31620 — Derick Rethans — 2007-08-16T08:33:17+00:00

URL: https://externals.io/message/31183#31620 · In reply to: #31604

> I didn't get any further, no :(. The decision of whether to merge the nowdocs
> patch is out of my hands now, since I don't have source karma. However, since
> the main thing standing in the way of its implementation was concern over the
> usefulness, your comment is very helpful, and I'd like to open the topic for
> discussion again on the list, if no one out there has any objection :)

I don't see why this can not go into 5.3 once that branch is open. It 
seems pretty useful to me.

regards,
Derick

---

## #31641 — Stanislav Malyshev — 2007-08-16T19:07:49+00:00

URL: https://externals.io/message/31183#31641 · In reply to: #31604

> I didn't get any further, no :(. The decision of whether to merge the 
> nowdocs patch is out of my hands now, since I don't have source karma. 
> However, since the main thing standing in the way of its implementation 
> was concern over the usefulness, your comment is very helpful, and I'd 
> like to open the topic for discussion again on the list, if no one out 
> there has any objection :)

I think we can have it in HEAD and maybe in 5.3 - though it raises 
questions about compatibility (code not parsing in certain PHP versions 
and parsing in others might be a problem). Not sure if <<<~ is the best 
syntax - it's definitely not obvious, maybe we could think of something 
better.
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #31657 — Pierre — 2007-08-16T21:03:52+00:00

URL: https://externals.io/message/31183#31657 · In reply to: #31641

> > […]
>
> I think we can have it in HEAD and maybe in 5.3 - though it raises
> questions about compatibility (code not parsing in certain PHP versions
> and parsing in others might be a problem).

I don't see a difference between a "fatal error call to undefined
function" and or a parse error. It can go without problem in 5.3.


> Not sure if <<<~ is the best
> syntax - it's definitely not obvious, maybe we could think of something
> better.

<<< was never obvious, there is no obvious string to use in this case
(not obvious for everyone and his mother).

--Pierre

---

## #31659 — Stanislav Malyshev — 2007-08-16T23:24:32+00:00

URL: https://externals.io/message/31183#31659 · In reply to: #31657

> I don't see a difference between a "fatal error call to undefined
> function" and or a parse error. It can go without problem in 5.3.

Ah, there is a difference - you can do function_exists to check for a 
function, but you can do nothing if your file doesn't parse.

> <<< was never obvious, there is no obvious string to use in this case
> (not obvious for everyone and his mother).

Perl does <<FOO and <<'FOO' and I think in this case difference is more 
clear. I'm not sure this is the way, but it can be an option. Everybody 
is welcome to propose - maybe it will be as much fun as the namespace 
separator thread ;)
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #31666 — Pierre — 2007-08-17T05:32:09+00:00

URL: https://externals.io/message/31183#31666 · In reply to: #31659

> > […]
>
> Ah, there is a difference - you can do function_exists to check for a
> function, but you can do nothing if your file doesn't parse.

True, but the result is the same. The new functions/classes can't be
used (only some rare additions can be efficiently emulated in user
land).

> > […]
>
> Perl does <<FOO and <<'FOO' and I think in this case difference is more
> clear. I'm not sure this is the way, but it can be an option. Everybody
> is welcome to propose - maybe it will be as much fun as the namespace
> separator thread ;)

In this case, it will be yet another "Mark all as read" thread :-)

Cheers,
--Pierre

---

## #31709 — Stanislav Malyshev — 2007-08-17T17:57:14+00:00

URL: https://externals.io/message/31183#31709 · In reply to: #31666

> True, but the result is the same. The new functions/classes can't be
> used (only some rare additions can be efficiently emulated in user
> land).

Yes, but you still have option of working around it. Right now we don't 
have an option to work around new syntax. I hate to rain on your parade, 
because I think this functionality is good and would have a lot of good 
uses, but I'm worried about creating code that runs in one 5.x and can't 
be even compiled by another. There can be a lot of problems with 
external tools, too.
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #31712 — Pierre — 2007-08-17T18:59:55+00:00

URL: https://externals.io/message/31183#31712 · In reply to: #31709

> > […]
>
> Yes, but you still have option of working around it. Right now we don't
> have an option to work around new syntax. I hate to rain on your parade,
> because I think this functionality is good and would have a lot of good
> uses, but I'm worried about creating code that runs in one 5.x and can't
> be even compiled by another. There can be a lot of problems with
> external tools, too.

I agree about codes not running in the same "bug fixes" branch.
However I don't see a problem to introduce this patch in 5.3.0 (think
about "b" introduced in 5.2.x).

--Pierre
