Re: RFC: Short echo tag can also call closures
| From: | Bruce Weirdan | Date: | Mon, 18 Sep 2023 19:12:40 +0000 |
| Subject: | Re: RFC: Short echo tag can also call closures | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121096@lists.php.net to get a copy of this message | ||
I think it's a non-starter because it would change how the existing
code is interpreted.
E.g. currently
```
<?php $title = 'rand'; ?>
<h1><?= $title ?></h1>
```
outputs
rand, but with your proposal it would invoke rand() and
output its result.
On Mon, Sep 18, 2023 at 8:19 PM Shailesh Humbad
<shailesh@atensoftware.com> wrote:
>
> Hello,
>
> I'm gauging interest on a proposed change to the short echo tag "<?=".
>
> CURRENTLY:
> The short echo tag "<?= $x ?>" is equivalent to "<?php echo $x
> ?>",
> which allows for beautiful MVC views like this:
>
> <html>
> <head><title><?= $model->title ?></title></head>
> <body><?= $model->body ?></body>
> </html>
>
> INSTEAD:
> Change the short echo tag "<?= $x ?>" to be equivalent to "<?php
> is_callable($x) ? $x() : echo $x; ?>", which allows view model
> properties to be defined as closures. This syntactic sugar would
> encourage higher-performance coding practices, since it allows for
> content to be streamed rather than buffered into memory before being
> output. (Note that there is no need to pass any parameters to the
> closure, or even have that as an option.) Here is a sample:
>
> $model = new StdClass();
> $FileName = 'LargeFile.html';
> $model->bodyStream = function () use $FileName { readfile($FileName); };
>
> <html>
> <head><title><?= $model->title ?></title></head>
> <body><?= $model->bodyStream ?></body>
> </html>
>
> Thank you for considering!
>
> Regards,
> Shailesh
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>
--
Best regards,
Bruce Weirdan mailto:weirdan@gmail.com