Hi!
Firt of all thank you a lot for this RFC! It's a great idea!

I have one small addition.

PHP already provides a way to write extensions that hook into AST parsing.
However, it's too coarse grained. It forces you to intercept the entire AST
pipeline instead of extending PHP's behavior at specific points.

It would be much cleaner and honestly much cooler to make the PHP parser
extensible at well defined extension points. That would enable not only
JSX-like syntax, but also QL-like expressions to be integrated into PHP
cleanly.

In that case, PHP could provide them as separate ext modules.

Best Regards, Ed!

ср, 15 июл. 2026 г. в 16:11, Liam Hammett <[email protected]
>:

> Hi internals,
>
> I'd like to open discussion on a new RFC, "Native Markup Expressions":
>
> RFC: https://wiki.php.net/rfc/native_markup_expressions
> Implementation (with tests): https://github.com/php/php-src/pull/22661
>
> It proposes a native syntax for HTML fragments as first-class PHP
> expressions,
> akin to how the frontend community has adopted JSX, with composition and
> escape-by-default output:
>
>
>     class Greeting implements Markup\Html
>     {
>         public function __construct(public string $name) {}
>
>         public function toHtml(): Markup\Html
>         {
>             return <>
>                 <h1 class="title">Hello, {$this->name}!</h1>
>                 <p>Welcome to PHP, where markup is a first-class
>                 expression.</p>
>             </>;
>         }
>     }
>
>     echo <Greeting name="Rasmus" />; // rendered HTML, values escaped
>
>
> Despite appearances, this is not a template language grafted onto the
> engine -
> the syntax is pure compile-time sugar. Every markup expression lowers
> during compilation to a plain `new` expression:
>
>
>     $html = <button class="btn">Sign in</button>;
>     // compiles to exactly:
>     $html = new \Markup\Element('button', ['class' => 'btn'], ['Sign in']);
>
>
> The RFC already answers many anticipated questions, and I am open
> to making further adjustments so this can become a feature the whole
> community benefits from.
>
> Looking forward to your feedback.
>
> Best regards,
> Liam
>

Reply via email to