# Another tiny syntax patch

- Thread: https://externals.io/message/45094
- Original archive: https://news-web.php.net/php.internals/45094
- Started by Gwynne Raskind on 2009-07-26T09:12:54+00:00
- Messages: 3
- 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

---

## #45094 — Gwynne Raskind — 2009-07-26T09:12:54+00:00

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

For the sake of the heck of it, I'm gonna offer up this tiny patch I'm  
using in one of my projects. I don't really care if it gets included  
in anything or not, just thought it might interest someone.

Effect: Adds a "<?php=" syntax which behaves identically to "<?=", but  
works without the use of short_tags.
Caveat: The formation "<?php=" is not valid XML. Specifically, section  
2.6 of [1] defines a PITarget as a Name, which in turn is made up of  
NameChars (section 2.3), which do not include the "=" character.
Advantage: Saves five characters of typing. "<?php= $myvar ?>" versus  
"<?php echo $myvar; ?>".

Just thought I'd throw it out there.

Index: Zend/zend_language_scanner.l
===================================================================
--- Zend/zend_language_scanner.l	(revision 286353)
+++ Zend/zend_language_scanner.l	(working copy)
@@ -1537,6 +1588,15 @@
  }


+<INITIAL>"<?php=" {
+	zendlval->value.str.val = yytext; /* no copying - intentional */
+	zendlval->value.str.len = yyleng;
+	zendlval->type = IS_STRING;
+	BEGIN(ST_IN_SCRIPTING);
+	return T_OPEN_TAG_WITH_ECHO;
+}
+
+
  <INITIAL>"<?php"([ \t]|{NEWLINE}) {
  	zendlval->value.str.val = yytext; /* no copying - intentional */
  	zendlval->value.str.len = yyleng;

[1] Extensible Markup Language (XML) 1.0 Fifth Edition, http://www.w3.org/TR/2008/REC-xml-20081126/

-- Gwynne

---

## #45095 — Rasmus Lerdorf — 2009-07-26T09:17:12+00:00

URL: https://externals.io/message/45094#45095 · In reply to: #45094

We have talked about this before, and the conclusion was that if we are
going to have an invalid PI, we might as well make it <?= since it is
just as invalid as <?php= and just as easy to parse.  Now you save 8 chars.

-Rasmus

Gwynne Raskind wrote:
> For the sake of the heck of it, I'm gonna offer up this tiny patch I'm
> using in one of my projects. I don't really care if it gets included in
> anything or not, just thought it might interest someone.
> 
> Effect: Adds a "<?php=" syntax which behaves identically to "<?=", but
> works without the use of short_tags.
> Caveat: The formation "<?php=" is not valid XML. Specifically, section
> 2.6 of [1] defines a PITarget as a Name, which in turn is made up of
> NameChars (section 2.3), which do not include the "=" character.
> Advantage: Saves five characters of typing. "<?php= $myvar ?>" versus
> "<?php echo $myvar; ?>".
> 
> Just thought I'd throw it out there.
> 
> Index: Zend/zend_language_scanner.l
> ===================================================================
> --- Zend/zend_language_scanner.l    (revision 286353)
> +++ Zend/zend_language_scanner.l    (working copy)
> @@ -1537,6 +1588,15 @@
>  }
> 
> 
> +<INITIAL>"<?php=" {
> +    zendlval->value.str.val = yytext; /* no copying - intentional */
> +    zendlval->value.str.len = yyleng;
> +    zendlval->type = IS_STRING;
> +    BEGIN(ST_IN_SCRIPTING);
> +    return T_OPEN_TAG_WITH_ECHO;
> +}
> +
> +
>  <INITIAL>"<?php"([ \t]|{NEWLINE}) {
>      zendlval->value.str.val = yytext; /* no copying - intentional */
>      zendlval->value.str.len = yyleng;
> 
> [1] Extensible Markup Language (XML) 1.0 Fifth Edition,
> http://www.w3.org/TR/2008/REC-xml-20081126/
> 
> -- Gwynne

---

## #45096 — Gwynne Raskind — 2009-07-26T09:30:35+00:00

URL: https://externals.io/message/45094#45096 · In reply to: #45095

> We have talked about this before, and the conclusion was that if we  
> are
> going to have an invalid PI, we might as well make it <?= since it is
> just as invalid as <?php= and just as easy to parse.  Now you save 8  
> chars.

I prefer strong namespacing of all my tags. "<?" and "<?=" are highly  
generic and could be usurped by any other (admittedly finctional so  
far) processing system run on the file.

As I said, it was just for the heck of it :). I know no one's likely  
to find it interesting.

I did toy with the idea of something that was actually compliant, but:

<?php.	- is not visually distinctive
<?php-	- same
<?php.e	- saves very little typing and is ugly
<?phpe	- mucks with the entire idea of being namespaced
<?php e	- visually confusing and saves little typing

And so forth.

> Gwynne Raskind wrote:
> > […]

-- Gwynne
