On Mon, Sep 18, 2023 at 8:18 PM Shailesh Humbad
<shail...@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
>

Hello,

You can basically already do something like this:

<?= r($model->title) ?>

where `r()` implements the desired logic. You should be escaping
things when outputting anyway, and this function could handle exactly
that.


Robert Landers
Software Engineer
Utrecht NL

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to