PHP 是一种模板语言。 虽然我同意实现 MVC 的概念,但我不明白为什么需要围绕生成 Web 输出实现另一个 DSL。
I disagree with this one:
Don't blindly embed PHP into HTML - use templating/MVC.
PHP is a templating language. While I agree with the concept of implementing MVC, I don't see why there should be a requirement to implement a yet another DSL around producing web output.
Adding closing "?>" tags to the end of php files can lead to accidentally pushing white-spaces to the output buffer. The PHP interpreter will automatically add closing tags to files, and doing it manually is somewhat of an anti-pattern.
My current pet peeve is inconsistent-return-type for query-functions. This is when you call a function to execute a query, and it returns
NULL or FALSE or something similar when no match is found
The matching object/value when a single match is found
array of matching objects/values when more than one match was found
which forces you to check the return types and deal with each case specifically. It would be much better to simply always return an array with 0, 1 or n elements.
If I had to include a favourite don't it has to be the one posted by karim79:
$query = 'select * from users where username = ' . $_POST['username'];
Many developers in PHP keep stuck in structured age. PHP supports classes and objects since a while ago, I just don't get why people keep hard coding PHP into html, without templates or nothing at all.
I believe that developers from other languages, like .NET or Java have earned the right to criticize the language if so many developers keep programming like that. PHP is a very great language, very flexible, still a little junior but is growing, but many just don't get it, all they want is to solve by making the old classic copy & paste.
发布评论
评论(7)
我不同意这一点:
PHP 是一种模板语言。 虽然我同意实现 MVC 的概念,但我不明白为什么需要围绕生成 Web 输出实现另一个 DSL。
I disagree with this one:
PHP is a templating language. While I agree with the concept of implementing MVC, I don't see why there should be a requirement to implement a yet another DSL around producing web output.
添加结束符“?>” 将标签添加到 php 文件末尾可能会导致意外地将空格推入输出缓冲区。 PHP 解释器会自动向文件添加结束标签,而手动执行此操作在某种程度上是一种反模式。
Adding closing "?>" tags to the end of php files can lead to accidentally pushing white-spaces to the output buffer. The PHP interpreter will automatically add closing tags to files, and doing it manually is somewhat of an anti-pattern.
$_GET
或$_POST
。php.ini
权限。index.php
中。$_SESSION
中。$_GET
or$_POST
without checking it and cleaning it up.php.ini
right.index.php
.$_SESSION
.我目前最讨厌的是查询函数的返回类型不一致。 这是当您调用函数来执行查询时,
这迫使您检查返回类型并具体处理每种情况。 最好总是返回一个包含 0、1 或 n 个元素的数组。
My current pet peeve is inconsistent-return-type for query-functions. This is when you call a function to execute a query, and it returns
which forces you to check the return types and deal with each case specifically. It would be much better to simply always return an array with 0, 1 or n elements.
我最喜欢的“不要”之一是:
它还能变得比这更可怕吗?
One of my favourite DON'Ts would have to be:
Can it get much scarier than that?
如果我必须列出最喜欢的一个,那一定是 karim79 发布的那个:
许多 PHP 开发人员一直停留在结构化时代。 PHP 从前一段时间就支持类和对象,我只是不明白为什么人们不断将 PHP 硬编码为 html,没有模板或什么都没有。
我相信,如果有这么多开发人员继续这样编程,那么来自其他语言(例如 .NET 或 Java)的开发人员就赢得了批评该语言的权利。 PHP 是一门非常伟大的语言,非常灵活,仍然有点初级,但正在成长,但许多人就是不明白它,他们想要的只是通过制作旧的经典副本和 PHP 来解决。 粘贴。
If I had to include a favourite don't it has to be the one posted by karim79:
Many developers in PHP keep stuck in structured age. PHP supports classes and objects since a while ago, I just don't get why people keep hard coding PHP into html, without templates or nothing at all.
I believe that developers from other languages, like .NET or Java have earned the right to criticize the language if so many developers keep programming like that. PHP is a very great language, very flexible, still a little junior but is growing, but many just don't get it, all they want is to solve by making the old classic copy & paste.