gpt4 book ai didi

php - HEREDOC 干扰代码缩进

转载 作者:IT王子 更新时间:2023-10-28 23:52:45 27 4
gpt4 key购买 nike

我喜欢 HEREDOC 语法,例如对于不值得放入模板的生成 HTML 的边缘情况。

不过,唯一让我恼火的是内容和 heredoc 字符串的结束标记紧贴第一列。这搞砸了嵌套代码布局:

class myclass 
{

function __construct()
{
$a = some_code();
$b = some_more_code();
$x = <<<EOT

line1
line2
line3
line4

EOT;

$c = even_more_code();
$b = still_more_code();
...
...
...

你明白我的意思了。

现在这可能无法使用普通的 HEREDOC 解决。有人解决过这个问题吗?我的梦想是拥有带自动缩进的 HEREDOC 语法。但我想如果不为源文件编写一些预编译器,这是不可能的。

我说的对吗?

最佳答案

谢天谢地,此功能终于通过 RFC 登陆 php 7.3:Flexible Heredoc and Nowdoc Syntaxes

现在您的示例可以清晰地写为:

class myclass
{
function __construct()
{
$a = some_code();
$b = some_more_code();
$x = <<<EOT

line1
line2
line3
line4

EOT;

$c = even_more_code();
$b = still_more_code();
}
}

关于php - HEREDOC 干扰代码缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2305869/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com