大型项目没有PHP ?为什么不呢?

时间:2023-01-16 16:57:06

I've read a few posts where people have stated (not suggested, not discussed, not offered) that PHP should not be used for large projects.

我读过一些文章,人们已经声明(不建议,不讨论,不提供)PHP不应该用于大型项目。

Being a primarily PHP developer, I ask two questions:

作为一个主要的PHP开发人员,我有两个问题:

  1. What defines a "large project"?
  2. 什么定义了“大项目”?
  3. Why not? What are the pitfalls of using PHP
  4. 为什么不呢?使用PHP的缺陷是什么

I run a small development team and I know from experience the quality construction, organization, documentation, commenting and encapsulation are our highest priority. We are able to develop great projects using our own framework and approach but still, I don't want to invest further if I'm wasting my time.

我管理着一个小型的开发团队,从经验中我知道质量建设、组织、文档、注释和封装是我们的首要任务。我们可以用我们自己的框架和方法开发伟大的项目,但是,如果我在浪费时间,我还是不想进一步投资。

Thoughts?

想法吗?

11 个解决方案

#1


86  

I really hate it when people say flat out that PHP is a terrible language because you can write code which mixes presentation with logic, or that it lets you allow SQL injection. That's nothing at all to do with the language, that's the developer.

我真的很讨厌人们说PHP是一种糟糕的语言,因为你可以编写将表示与逻辑结合在一起的代码,或者它允许SQL注入。这与语言没有任何关系,这是开发人员。

PHP has proved itself to be highly scalable: Wikipedia is one of the largest and most popular sites on the Internet and it runs PHP. Enough said?

PHP已经证明了自己是高度可伸缩的:*是互联网上最大和最流行的网站之一,它运行PHP。足够的说吗?

There are a lot of tools/libraries out there that give you a framework to work in, making it less likely that someone will write poor, less-maintainable code: see CakePHP, Symfony, PDO, Smarty, etc etc etc.

有很多工具/库可以为您提供一个框架,使您不太可能编写糟糕的、难于维护的代码:参见CakePHP、Symfony、PDO、Smarty等。

It has received a bad rap because it's a language which has very low barriers to entry: it's free, you can get very cheap PHP hosting, the documentation is the best there is, there's plenty of tutorials online, plus it makes a lot of things very easy (eg: open a URL and get the contents of the file: file('http://www.google.com');). This means that a lot of newbies picked it up and made a lot of very dodgy sites with it, but that's going to happen with whatever language you choose as your first.

它已经收到了一个坏名声,因为它是一个语言门槛非常低:它是免费的,你可以得到非常便宜PHP托管,文档是最好的,网上有很多教程,加上它让很多事情非常简单(如:打开一个URL和文件的内容:文件(“http://www.google.com”);)。这就意味着很多新手会用它来创建很多非常危险的网站,但是不管你选择什么语言作为你的第一语言,这种情况都会发生。

Work with a solid ORM framework (there's about 30 questions on SO about which is best), and it will treat you good.

使用一个坚实的ORM框架(大约有30个问题关于哪个是最好的),它会对你有好处。

#2


30  

A lot of people who say not use it are really saying don't use PHP 4. It comes down to this

很多说不使用的人实际上是说不使用PHP 4。归根结底就是这个

you can write good code in any language

你可以用任何语言编写好的代码。

and

you can write bad code in any language

您可以用任何语言编写糟糕的代码

PHP can very often lend itself to becoming tangled spaghetti code libraries and make your 'application' really just a series of scripts (see Moodle for a good example of this...)

PHP常常会使您的“应用程序”变成一个混乱的意大利面条式代码库,而实际上只是一系列脚本(请参阅Moodle,以获得一个很好的示例…)

I think a lot of the 'Don't use PHP for large stuff' is coming from PHP being hacked up from it's original purpose: a templating language. Which I can understand, but there are lots of projects that prove you can do it (Drupal, mediawiki, Facebook).

我认为很多“不要把PHP用在大事情上”都来自于PHP,因为它的初衷是:一种模板语言。我能理解,但是有很多项目可以证明你可以做到(Drupal, mediawiki, Facebook)。

#3


18  

Theres no reason you can't use PHP for large projects. After all, Facebook is built on PHP. There will be issues however but there are issues with any large project.

对于大型项目,没有理由不使用PHP。毕竟,Facebook是建立在PHP之上的。但也会有一些问题,但任何大型项目都有问题。

What makes PHP so pervasive is the low barrier to entry and cheap hosting. It runs as an Apache extension and you can pretty much just start coding. If you go to more enterprise platforms such as .Net or Java, they have a much higher barrier to entry but they also come with a lot of infrastructure to help you make applications that scale.

PHP如此普及的原因在于其进入门槛低、托管成本低。它作为Apache扩展运行,您几乎可以开始编写代码。如果您使用更多的企业平台,如. net或Java,它们的进入门槛要高得多,但是它们也提供了大量的基础设施来帮助您实现应用程序的扩展。

For example, the database abstraction in PHP is (imho) woeful. It's vendor specific. With MySQL, people tend to do things like:

例如,PHP中的数据库抽象(imho)很糟糕。它是特定于供应商的。使用MySQL,人们倾向于做以下事情:

function get_users($surname) {
  mysql_query("select * from users where surname = '$surname'");
  ...
}

which is bad for several reasons:

这有几个不好的原因:

  • It makes poor use of the query cache;
  • 它对查询缓存的使用很差;
  • It doesn't handle escaping of characters (which, of course, can be done with mysql_escape_string() but you'll be surprised how often people don't do this); and
  • 它不处理字符的转义(当然,可以使用mysql_escape_string()进行转义,但是您会惊奇地发现人们很少这样做);和
  • It's fairly easy to code in such a way as to allow SQL injection attacks.
  • 使用SQL注入攻击的方式编写代码相当容易。

Personally I prefer mysqli for all the above reasons but it has it's own problems: namely that using LONGTEXT fields crashes mysql and has done since at least 2005 with still no fix (yes I and several others have raised a bug).

就我个人而言,出于以上所有原因,我更喜欢sqmyli,但它也有它自己的问题:即使用长文本字段会导致mysql崩溃,而且至少从2005年开始,还没有修复(是的,我和其他一些人提出了一个bug)。

Compare this to Java (with which I'm more familiar) and JPA or Ibatis are vastly better ORM solutions with higher startup costs but they will help you on an enterprise scale.

与Java(我对此更熟悉)相比,JPA或Ibatis是更好的ORM解决方案,启动成本更高,但它们将在企业规模上帮助您。

So you're not prohibited from doing large projects on PHP. It's simply harder in that you have to do increasingly more work yourself to replicate what other platforms provide you.

因此,不禁止您在PHP上执行大型项目。更困难的是你必须自己做更多的工作来复制其他平台提供给你的东西。

That being said, PHP + memcached/APC + beanstalkd goes a long way.

话虽如此,PHP + memcached/APC + beanstalkd还有很长的路要走。

Oh that's the other problem: PHP doesn't really support background processing or threading. You need something else for that (or standalone scripts). If you're using something else, why not use that for the Web stuff too (eg Java, Ruby, .Net, etc)?

这是另一个问题:PHP不支持后台处理或线程。您需要一些其他的东西(或独立的脚本)。如果您正在使用其他东西,为什么不将其用于Web内容(例如Java、Ruby、.Net等)?

#4


16  

As the question I linked was deleted, I'll place some of it here:

由于我链接的问题被删除,我将在这里放一些:

Question


I made a tongue-in-cheek comment in another question thread calling PHP a terrible language and it got down-voted like crazy. Apparently there are lots of people here who love PHP.

我在另一个问题上做了个半开玩笑的评论,说PHP是一种糟糕的语言,它被疯狂地否决了。显然这里有很多人喜欢PHP。

So I'm genuinely curious. What am I missing? What makes PHP a good language?

所以我真的很好奇。我缺少什么?是什么让PHP成为一种好语言?

Here are my reasons for disliking it:

以下是我不喜欢它的原因:

  • PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.

    PHP内建函数和库函数的命名不一致。可预测的命名模式在任何设计中都很重要。

  • PHP has inconsistent parameter ordering of built-in functions, eg array_map vs. array_filter which is annoying in the simple cases and raises all sorts of unexpected behaviour or worse.

    PHP内建函数的参数排序不一致,比如array_map和array_filter,这在简单的情况下很烦人,会引起各种意想不到的行为,甚至更糟。

  • The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions. This created a nightmare for anyone doing, say, function callbacks.

    PHP开发人员经常不赞成使用内置函数和低级功能。一个很好的例子是当它们不赞成函数的引用传递时。这对任何执行函数回调的人来说都是一场噩梦。

  • A lack of consideration in redesign. The above deprecation eliminated the ability to, in many cases, provide default keyword values for functions. They fixed this in PHP 5, but they deprecated the pass-by-reference in PHP 4!

    重新设计时缺乏考虑。上面的弃用消除了在许多情况下为函数提供默认关键字值的能力。他们在PHP 5中修复了这个问题,但是他们不赞成PHP 4中的pass-by引用!

  • Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!

    名称空间执行不力(以前根本没有名称空间)。现在有了名称空间,我们用什么作为删除引用字符?反斜杠!通用的转义字符,甚至在PHP中也是如此!

  • Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.

    范围太广的隐式类型转换会导致错误。我对隐式转换没有问题,比方说,浮点到整数或返回。但是PHP(最后我检查过)会很高兴地尝试将数组转换成整数。

  • Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.

    可怜的递归的性能。递归是用任何语言写东西的重要工具;它可以使复杂的算法简单得多。可怜的支持是不可原谅的。

  • Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.

    函数是不区分大小写。我不知道他们在想什么。编程语言是一种为计算机和代码读者指定行为的方法,没有歧义。大小写不敏感会引起歧义。

  • PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.

    PHP鼓励(实际上需要)处理与表示的耦合。是的,您可以编写不这样做的PHP,但实际上更容易以不正确的方式(从声音设计的角度)编写代码。

  • PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.

    没有缓存,PHP性能就糟糕透顶。是否有人销售用于PHP的商业缓存产品?哦,看,PHP的设计者会这么做。

Worst of all, PHP convinces people that designing web applications is easy. And it does indeed make much of the effort involved much easier. But the fact is, designing a web application that is both secure and efficient is a very difficult task.

最糟糕的是,PHP让人们相信设计web应用程序很容易。而且它确实使所涉及的许多努力变得容易得多。但事实是,设计一个既安全又高效的web应用程序是一项非常困难的任务。

By convincing so many to take up programming, PHP has taught an entire subgroup of programmers bad habits and bad design. It's given them access to capabilities that they lack the understanding to use safely. This has led to PHP's reputation as being insecure.

通过说服如此多的人从事编程,PHP已经教会了整个程序员群体坏习惯和坏设计。它给了他们安全使用所缺乏的能力。这导致了PHP的不安全声誉。

(However, I will readily admit that PHP is no more or less secure than any other web programming language.)

(不过,我很乐意承认PHP并不比任何其他web编程语言更安全。)

What is it that I'm missing about PHP? I'm seeing an organically-grown, poorly-managed mess of a language that's spawning poor programmers.

关于PHP我缺少什么?我看到的是一种有机生长的、管理不善的语言的混乱,它正在催生可怜的程序员。

So convince me otherwise!

所以说服我否则!


Top Rated Answer


I'll take a stab at responding to each of your bullet points

我会尝试着回答你的每一个要点

PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.

PHP内建函数和库函数的命名不一致。可预测的命名模式在任何设计中都很重要。

I both love and hate this topic. Because at its core, this issue is correct. Why are some bi-word function split with an underscore, and some aren't? Why do needle and haystack parameters swap positions in the argument signature sometimes? It's ridiculous. But at the end of the day... does this really matter? My IDE with intellisense and php.net just a browser click away, this is just plain not that big of a deal. Is it a negative against PHP as a language? Yes. Does it hinder my ability to be an effective programmer? No.

我既喜欢又讨厌这个话题。因为这个问题的核心是正确的。为什么有些双字函数用下划线拆分,有些却不是?为什么指针和haystack参数有时会交换参数签名中的位置?这是荒谬的。但最后……这真的重要吗?我的IDE有智能感知和php。net浏览器点击一下,这没什么大不了的。它对PHP作为一种语言有负面影响吗?是的。它是否会妨碍我成为一名有效的程序员的能力?不。

The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions. This created a nightmare for anyone doing, say, function callbacks.

PHP开发人员经常不赞成使用内置函数和低级功能。一个很好的例子是当它们不赞成函数的引用传递时。这对任何执行函数回调的人来说都是一场噩梦。

Personally, I think this is not a good point. Deprecation is necessary to the evolution of a language, especially one that has as much kruft as PHP does. PHP gets a lot of flak for "making it easy to be a bad programmer*" but at the same time, the PHP group also gets in trouble when they try to remove stupid constructs from the language, such as call-time pass-by-reference. Eliminating call-time pass-by-reference was one of the best moves they ever made. There was no easier way for a novice developer to shoot themselves in the foot than with this "feature".

我个人认为这不是一个好的观点。对语言的发展来说,弃用是必要的,尤其是像PHP一样拥有大量kruft的语言。PHP因为“让人很容易成为一个糟糕的程序员*”而受到很多指责,但与此同时,当PHP组试图从语言中删除愚蠢的构造(如调用时传递引用)时,也会遇到麻烦。消除按引用进行的呼叫时间传递是他们所做过的最好的步骤之一。对于新手开发人员来说,没有比使用这个“特性”更容易的方法了。

A lack of consideration in redesign. The above deprecation eliminated the ability to, in many cases, provide default keyword values for functions. They fixed this in PHP 5, but they deprecated the pass-by-reference in PHP 4!

重新设计时缺乏考虑。上面的弃用消除了在许多情况下为函数提供默认关键字值的能力。他们在PHP 5中修复了这个问题,但是他们不赞成PHP 4中的pass-by引用!

I don't think there's a general lack of consideration at all, I think you just got stung by this particular change and have been left with a sour taste in your mouth. Language changes are often known months if not years ahead of time. A migration guide was provided for the move from 4 to 5, and the version differences are documented in the manual. Call-time pass-by-reference was a horrible "feature" and doesn't give the developer any expressive power they can't get by other means. I'm glad it is gone (along with other crap like magic quotes)

我不认为人们普遍缺乏考虑,我认为你只是被这种特殊的变化所刺痛,并留下一个酸的味道在你的嘴里。语言的变化即使不是提前几年,也是几个月。为从4到5的迁移提供了迁移指南,并且在手册中记录了版本差异。调用时间传递引用是一个可怕的“特性”,它没有给开发人员任何其他方式无法获得的表达能力。我很高兴它消失了(还有其他的废话,比如神奇的名言)

Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!

名称空间执行不力(以前根本没有名称空间)。现在有了名称空间,我们用什么作为删除引用字符?反斜杠!通用的转义字符,甚至在PHP中也是如此!

I have mixed feelings about this. Part of me thinks "who cares, character escaping has no meaning outside of a string anyway", and part of me thinks "surely they could use something better". But could they? I don't know, I'm not a developer for the Zend parser. Is it a huge oversight that until 5.3 PHP never had namespaces at all? Yes, absolutely.

我对此有复杂的感觉。我的一部分人认为“谁在乎呢,字符转义在字符串之外没有任何意义”,而我的一部分人认为“他们肯定会用更好的东西”。但他们吗?我不知道,我不是Zend解析器的开发人员。直到5.3 PHP根本没有名称空间,这是一个巨大的疏忽吗?是的,当然。

Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.

范围太广的隐式类型转换会导致错误。我对隐式转换没有问题,比方说,浮点到整数或返回。但是PHP(最后我检查过)会很高兴地尝试将数组转换成整数。

I think it's ok to disagree with how PHP does this, but disagree that it makes the language "bad". But ask me how much I want to sit in this topic and argue about weak vs strong typing. (P.S. I don't, at all) For the record: PHP will issue an E_WARNING level error when the type of an argument matters and cannot by solved by coercion.

我认为不同意PHP是如何做到这一点的,但不同意它让语言变得“糟糕”。但是,问问我,我有多想坐在这个话题上讨论弱打字和强打字。(顺便说一句,我一点也不知道)对于记录:当一个参数的类型有问题时,PHP会发出一个E_WARNING级别的错误,并且不能通过强制来解决。

Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.

可怜的递归的性能。递归是用任何语言写东西的重要工具;它可以使复杂的算法简单得多。可怜的支持是不可原谅的。

PHP is a DSL for the web. I've been doing it full-time for 8 years and have maybe used recursion 4 or 5 times, usually for some type of annoying directory or XML traversal. It's just not a pattern that is needed for web development that often. I'm not excusing the slow performance, but this is an academic issue far more than it is a production issue. If you need really powerful recursive performance, PHP is already the wrong language for you.

PHP是一种用于web的DSL。我已经全职使用它8年了,可能使用了4到5次递归,通常用于某些烦人的目录或XML遍历。这并不是web开发经常需要的模式。我并不是在为缓慢的表现辩解,但这是一个学术问题,而不是一个生产问题。如果您需要非常强大的递归性能,PHP对您来说已经是错误的语言了。

Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.

函数是不区分大小写。我不知道他们在想什么。编程语言是一种为计算机和代码读者指定行为的方法,没有歧义。大小写不敏感会引起歧义。

I totally 100% agree with this.

我百分之百的同意。

PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.

PHP鼓励(实际上需要)处理与表示的耦合。是的,您可以编写不这样做的PHP,但实际上更容易以不正确的方式(从声音设计的角度)编写代码。

*Hmmm, this topic sounds desperately familiar...

这个话题听起来非常熟悉……

But seriously, I find it remarkable that people will complain about a language that will absolutely 100% let you implement any output system you want (the sheer volume and style of PHP templating systems alone speaks to this) - OR - skip all that overhead and just output directly. This does not make PHP bad at all. It's part of what makes PHP good.

但认真地说,我发现值得注意的是,人们会抱怨一种完全允许您实现任何您想要的输出系统的语言(仅PHP模板系统的庞大容量和风格就说明了这一点)——或者——跳过所有这些开销,直接输出。这并不会使PHP变得糟糕。它是PHP的一部分。

PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.

没有缓存,PHP性能就糟糕透顶。是否有人销售用于PHP的商业缓存产品?哦,看,PHP的设计者会这么做。

Do you mean bytecode caching (like an accelerator), or output caching?

您是指字节码缓存(如加速器)还是输出缓存?

If the former, then I don't really know how much I care about this topic. Accelerators are free and easy to run. We could argue about why it isn't part of the language but in the end, I don't think it matters much.

如果是前者,我真的不知道我有多在乎这个话题。加速器是免费和容易运行。我们可以争论为什么它不是语言的一部分,但最后,我不认为它很重要。

If you are talking about output caching then I don't know what to say to you. ANY web project with significant traffic needs caching (seed podcast #27, for example). This is not a PHP-specific issue at all.

如果您正在讨论输出缓存,那么我不知道该对您说什么。任何具有重要流量的web项目都需要缓存(例如,种子播客#27)。这根本不是php特有的问题。

In summary, I think you consider PHP a "bad" language in a very academic fashion. And in your previous post you were probably voted down by people like me who use PHP to "get things done".

总之,我认为您认为PHP是一种非常学术的语言。在你之前的文章中,你可能被像我这样使用PHP来“完成任务”的人否决了。


Second Top Rated Answer


All your criticisms (and some more) are valid. You are allowed and even expected to hate PHP.

你所有的批评(还有更多的批评)都是正确的。您可以甚至期望讨厌PHP。

But, then again, it has some benefits:

但是,它也有一些好处:

  • Ubiquitous
  • 无处不在的
  • Fast (especially using opcode caches)
  • 快速(特别是使用操作码缓存)
  • Huge community (and great documentation)
  • 庞大的社区(和优秀的文档)
  • Works
  • 作品

Finally, you can overcome many if not all the downsides by writing good code you'd write in any other language. You can write solid, secure and good smelling code in PHP, which many times will run faster and be easier to host and to scale than many alternatives.

最后,您可以通过编写用任何其他语言编写的好代码来克服许多(如果不是所有的缺点的话)。您可以在PHP中编写可靠、安全且具有良好气味的代码,与许多替代方法相比,这些代码的运行速度更快、更容易托管和扩展。


Third Top Rated Answer


What is it that I'm missing about PHP? I'm seeing an organically-grown, poorly-managed mess of a language that's spawning poor programmers.

关于PHP我缺少什么?我看到的是一种有机生长的、管理不善的语言的混乱,它正在催生可怜的程序员。

Simple. The fact that poor programmers get very defensive about their language. ;) PHP is easy to learn, much easier than the alternatives, and once you've learned it, it's not exactly obvious 1) what's wrong with PHP, 2) how the alternatives are better, and 3) how to switch to, and learn, one of the alternatives.

简单。糟糕的程序员对他们的语言非常抵触。,)PHP很容易学,比其他选项容易得多,一旦你学过了,就会发现1)PHP有什么问题,2)替代方案如何更好,3)如何切换到其中一个替代方案,并从中学习。

And perhaps the fact that, well, what alternatives do people have? ASP? That has plenty of problems on its own, from being unable to run on the majority of webservers (Apache), to some ridiculous and overengineered design choices on its own (webforms? Viewstate? AJAX where your asynchronous" requests are intercepted and run sequentially?) Ruby on Rails? Well, perhaps, except how many webservers support it again? It's not exactly easily approachable at the moment. And it's slow. So perhaps PHP's "strength" is really that no good alternative exists. At least this is why I stay away from all web programming when at all possible. PHP sucks, and I'm not too keen on any of the alternatives either.

也许事实上,人们有什么选择呢?ASP吗?这本身就有很多问题,从不能在大多数web服务器(Apache)上运行,到一些荒唐的、设计过度的选择(webforms?视图状态?在AJAX中,您的异步“请求被拦截并按顺序运行?)Ruby on Rails吗?嗯,也许,除了有多少网络服务器支持它?目前还不太容易接近。这是缓慢的。因此,也许PHP的“优势”实际上并不存在好的替代方案。至少这就是为什么我尽可能远离所有的web编程。PHP很糟糕,我也不太喜欢任何替代方案。

PHP has so many fundamental problems that it's not even funny. From the lack of unicode support, to the many implicit type conversions which often lead to unexpected security holes, to the complete mixing of presentation and... everything else, or to the default database module which doesn't (last I checked) use parametrized queries. We're talking about a language made for two things, database access and generating HTML, and which is terrible at both.

PHP有很多基本的问题,这一点都不好笑。从缺乏unicode支持,到许多隐式类型转换,常常导致意外的安全漏洞,到完整的表示和……其他的东西,或者默认的数据库模块(最后我检查过)没有使用参数化查询。我们说的是一种语言,它有两种功能:数据库访问和生成HTML,这两种语言都很糟糕。

It's just a nasty mess, a language designed by people who aren't qualified, or able, to design a language. ;)

这是一种令人讨厌的混乱,一种由不具备设计语言能力的人设计的语言。,)


#5


4  

For me the worst PHP sin is coupling of presentation with business logic. It's not that you can't write it in a better way, but it doesn't encourage you to, and if anything it encourages you not to.

对我来说,PHP最大的缺点是表示与业务逻辑的耦合。这并不是说你不能把它写得更好,而是它没有鼓励你这样做,如果有的话,它鼓励你不要这样做。

A large number of security vulnerabilities are associated with PHP sites, too. I can't prove it is disproportionate (after all a lot of sites are written in PHP), but I suspect it is. If I'm right, then since security vulnerabilities are a class of bug, I suspect PHP sites tend to be more buggy on the whole also.

许多安全漏洞也与PHP站点相关。我无法证明它是不相称的(毕竟很多网站都是用PHP编写的),但我怀疑它是不相称的。如果我是对的,那么既然安全漏洞是一类bug,那么我怀疑PHP站点在整体上也会更加糟糕。

(I don't think that pointing at a few large sites and saying they managed to do it in PHP is any argument against this, by the way. It's a bit like saying that cigarettes don't cause cancer because your next door neighbour smoked and lived to be 100.)

(顺便说一句,我不认为指向几个大型网站并说他们在PHP中成功地做到了这一点是任何反对这一点的理由。这有点像说香烟不会致癌,因为你的邻居吸烟,活到100岁。

#6


2  

Check out this similar question - Can PHP handle enterprise level sites as well as Java

看看这个类似的问题——PHP可以处理企业级站点,也可以处理Java

Recapping - Facebook, Wikipedia, Yahoo.com, Digg, Flickr and many other giant sites are running on PHP. If you ever come close to making something of that caliber, you can still rest assured you can get there with PHP.

Facebook、*、Yahoo.com、Digg、Flickr和许多其他大型网站都在使用PHP。如果您曾经接近实现这种水平,您仍然可以放心地使用PHP实现。

How maintainable, extendable, reliable, secure and performant your applications will be is entirely up to you and is language-agnostic. In favor of PHP though, it has very convenient tools for building web applications.

应用程序的可维护性、可扩展性、可靠性、安全性和性能将完全取决于您,并且与语言无关。不过,支持PHP的是,它有非常方便的工具来构建web应用程序。

#7


2  

For me, and talking about large or even huge projects, it (primarily) boils down to one word: Dependencies.

对我来说,谈到大型甚至是大型项目,它(主要)可以归结为一个词:依赖。

The problem with a scripting language is like in every thing in the world: The greatest advantage is the greatest disadvantage at the same time.

脚本语言的问题与世界上的任何事物一样:最大的优点同时也是最大的缺点。

The greatest advantage is to code free and fast. Just write a script and it will server it's purpose. No verbosity needed, simply code.

最大的优势是代码*和快速。只要写一个脚本,它就会实现它的目的。不需要冗长,只需编写代码。

The greatest disadvantage is, in a way, to check if this script is not disturbing other scripts. Or better: Change an old script others are relying on. Are you sure that all dependencies do work out as you desired?

最大的缺点是,在某种程度上,检查这个脚本是否没有干扰其他脚本。或者更好:改变别人依赖的旧剧本。您确定所有依赖项都按照您的要求工作吗?

This is not true for "normal" web page generation, whatever normal means here. But we have a product relying on some 500k lines of source code, with customizations for clients consisting of an additional 100k lines of code, too. And I am deadly glad that a compiler checks all dependencies and warns/errors me in case I did something wrong (like, speaking lowest level here, misstyping a variable or method call).

对于“正常”的web页面生成来说,这是不正确的,无论在这里是什么正常的方式。但我们的产品依赖于大约500k行源代码,客户端定制也包括额外的100k行代码。我非常高兴编译器检查所有依赖项并警告/出错,以防我做错了什么事情(比如,这里说的是最低级别,错误地设置变量或方法调用)。

I think this and the fact that other languages provide more simple-to-use "enterprisy" features by their nature (i.e. application servers for "bank usages") boils it down why many do not see PHP in large (or better: huge) projects.

我认为这一点,以及其他语言提供了更容易使用的“企业”特性(即“银行使用的应用服务器”)这一事实,可以归结为为什么许多人在大型(或更好的:大型)项目中看不到PHP。

#8


0  

Our company runs several large-ish web sites using PHP, and have had no problems that were related to the language.

我们公司使用PHP运行了几个大型web站点,并且没有遇到与语言相关的问题。

#9


0  

These are all good answers.

这些都是很好的答案。

I was a newbie. I've only been coding for 5 years but I directly support and manage 85 small to large websites and I'll tell you what, the potential to get sued by having a website down for a day will contribute a lot to your desire to learn how to and make better code.

我是一个新手。我只被编码为5年但我直接支持和管理85家小型到大型网站,我告诉你,可能被起诉通过一个网站一天下来会贡献很多你想学习如何更好的代码。

It's nice to hear established developers share their thoughts on this matter. I don't think PHP is the best, but it seems my investment in "best practices" is well served.

很高兴听到有开发的开发人员分享他们对这个问题的想法。我不认为PHP是最好的,但似乎我对“最佳实践”的投资得到了很好的服务。

Thanks everyone!

谢谢大家!

#10


0  

There's something about the construction of the PHP language that is not good enough for me. For example, the name of the functions. It is a non best practice use a several ways to name a function in one language. The mixture between underscores (function_name), words stick together (functionname), etc.I mean, this is really a mess. There are too many functions that are very similar or do the same things, but their names are so confusing. This is not characteristic of a good programming language.

PHP语言的构造对我来说还不够好。例如,函数的名称。使用多种方法在一种语言中命名函数不是最佳实践。下划线(function_name)和单词(functionname)之间的混合。我的意思是,这真是一团糟。有太多的函数非常相似或做相同的事情,但是它们的名字是如此令人困惑。这不是好的编程语言的特点。

In large deployments, the language must be enough easy and specific to write. Something that PHP omits like the declaration of variable types, become very difficult to understand and deal with later.

在大型部署中,语言必须足够简单和特定于编写。PHP省略了一些类似于变量类型声明的东西,以后很难理解和处理。

Other point is the constant addition of features and canceling of some other. It supposes that the addition of OOP in PHP 5 gonna make the things easier for programmers, but what about the considerations of back compatibility?

另一点是特征的不断增加和其他特征的抵消。它假设在PHP 5中添加OOP会使程序员的工作变得更容易,但是对于向后兼容性的考虑呢?

The principal reason that this programming language is like it is, is due to its origins: Personal Home Page. It was not designed for large deployments.

这种编程语言之所以如此,主要是因为它的起源:个人主页。它不是为大型部署而设计的。

I know that there are great efforts to make this language an enterprise-weight language, and personally, I'm waiting for a good enough open source server-side programming language; but until this day comes, it's gonna run a lot of water under the bridge.

我知道要使这种语言成为一种企业级的语言需要付出巨大的努力,就我个人而言,我正在等待一种足够好的开源服务器端编程语言;但在这一天到来之前,桥下会有很多水。

#11


0  

See: http://www.ukuug.org/events/linux2002/papers/html/php/

参见:http://www.ukuug.org/events/linux2002/papers/html/php/

#1


86  

I really hate it when people say flat out that PHP is a terrible language because you can write code which mixes presentation with logic, or that it lets you allow SQL injection. That's nothing at all to do with the language, that's the developer.

我真的很讨厌人们说PHP是一种糟糕的语言,因为你可以编写将表示与逻辑结合在一起的代码,或者它允许SQL注入。这与语言没有任何关系,这是开发人员。

PHP has proved itself to be highly scalable: Wikipedia is one of the largest and most popular sites on the Internet and it runs PHP. Enough said?

PHP已经证明了自己是高度可伸缩的:*是互联网上最大和最流行的网站之一,它运行PHP。足够的说吗?

There are a lot of tools/libraries out there that give you a framework to work in, making it less likely that someone will write poor, less-maintainable code: see CakePHP, Symfony, PDO, Smarty, etc etc etc.

有很多工具/库可以为您提供一个框架,使您不太可能编写糟糕的、难于维护的代码:参见CakePHP、Symfony、PDO、Smarty等。

It has received a bad rap because it's a language which has very low barriers to entry: it's free, you can get very cheap PHP hosting, the documentation is the best there is, there's plenty of tutorials online, plus it makes a lot of things very easy (eg: open a URL and get the contents of the file: file('http://www.google.com');). This means that a lot of newbies picked it up and made a lot of very dodgy sites with it, but that's going to happen with whatever language you choose as your first.

它已经收到了一个坏名声,因为它是一个语言门槛非常低:它是免费的,你可以得到非常便宜PHP托管,文档是最好的,网上有很多教程,加上它让很多事情非常简单(如:打开一个URL和文件的内容:文件(“http://www.google.com”);)。这就意味着很多新手会用它来创建很多非常危险的网站,但是不管你选择什么语言作为你的第一语言,这种情况都会发生。

Work with a solid ORM framework (there's about 30 questions on SO about which is best), and it will treat you good.

使用一个坚实的ORM框架(大约有30个问题关于哪个是最好的),它会对你有好处。

#2


30  

A lot of people who say not use it are really saying don't use PHP 4. It comes down to this

很多说不使用的人实际上是说不使用PHP 4。归根结底就是这个

you can write good code in any language

你可以用任何语言编写好的代码。

and

you can write bad code in any language

您可以用任何语言编写糟糕的代码

PHP can very often lend itself to becoming tangled spaghetti code libraries and make your 'application' really just a series of scripts (see Moodle for a good example of this...)

PHP常常会使您的“应用程序”变成一个混乱的意大利面条式代码库,而实际上只是一系列脚本(请参阅Moodle,以获得一个很好的示例…)

I think a lot of the 'Don't use PHP for large stuff' is coming from PHP being hacked up from it's original purpose: a templating language. Which I can understand, but there are lots of projects that prove you can do it (Drupal, mediawiki, Facebook).

我认为很多“不要把PHP用在大事情上”都来自于PHP,因为它的初衷是:一种模板语言。我能理解,但是有很多项目可以证明你可以做到(Drupal, mediawiki, Facebook)。

#3


18  

Theres no reason you can't use PHP for large projects. After all, Facebook is built on PHP. There will be issues however but there are issues with any large project.

对于大型项目,没有理由不使用PHP。毕竟,Facebook是建立在PHP之上的。但也会有一些问题,但任何大型项目都有问题。

What makes PHP so pervasive is the low barrier to entry and cheap hosting. It runs as an Apache extension and you can pretty much just start coding. If you go to more enterprise platforms such as .Net or Java, they have a much higher barrier to entry but they also come with a lot of infrastructure to help you make applications that scale.

PHP如此普及的原因在于其进入门槛低、托管成本低。它作为Apache扩展运行,您几乎可以开始编写代码。如果您使用更多的企业平台,如. net或Java,它们的进入门槛要高得多,但是它们也提供了大量的基础设施来帮助您实现应用程序的扩展。

For example, the database abstraction in PHP is (imho) woeful. It's vendor specific. With MySQL, people tend to do things like:

例如,PHP中的数据库抽象(imho)很糟糕。它是特定于供应商的。使用MySQL,人们倾向于做以下事情:

function get_users($surname) {
  mysql_query("select * from users where surname = '$surname'");
  ...
}

which is bad for several reasons:

这有几个不好的原因:

  • It makes poor use of the query cache;
  • 它对查询缓存的使用很差;
  • It doesn't handle escaping of characters (which, of course, can be done with mysql_escape_string() but you'll be surprised how often people don't do this); and
  • 它不处理字符的转义(当然,可以使用mysql_escape_string()进行转义,但是您会惊奇地发现人们很少这样做);和
  • It's fairly easy to code in such a way as to allow SQL injection attacks.
  • 使用SQL注入攻击的方式编写代码相当容易。

Personally I prefer mysqli for all the above reasons but it has it's own problems: namely that using LONGTEXT fields crashes mysql and has done since at least 2005 with still no fix (yes I and several others have raised a bug).

就我个人而言,出于以上所有原因,我更喜欢sqmyli,但它也有它自己的问题:即使用长文本字段会导致mysql崩溃,而且至少从2005年开始,还没有修复(是的,我和其他一些人提出了一个bug)。

Compare this to Java (with which I'm more familiar) and JPA or Ibatis are vastly better ORM solutions with higher startup costs but they will help you on an enterprise scale.

与Java(我对此更熟悉)相比,JPA或Ibatis是更好的ORM解决方案,启动成本更高,但它们将在企业规模上帮助您。

So you're not prohibited from doing large projects on PHP. It's simply harder in that you have to do increasingly more work yourself to replicate what other platforms provide you.

因此,不禁止您在PHP上执行大型项目。更困难的是你必须自己做更多的工作来复制其他平台提供给你的东西。

That being said, PHP + memcached/APC + beanstalkd goes a long way.

话虽如此,PHP + memcached/APC + beanstalkd还有很长的路要走。

Oh that's the other problem: PHP doesn't really support background processing or threading. You need something else for that (or standalone scripts). If you're using something else, why not use that for the Web stuff too (eg Java, Ruby, .Net, etc)?

这是另一个问题:PHP不支持后台处理或线程。您需要一些其他的东西(或独立的脚本)。如果您正在使用其他东西,为什么不将其用于Web内容(例如Java、Ruby、.Net等)?

#4


16  

As the question I linked was deleted, I'll place some of it here:

由于我链接的问题被删除,我将在这里放一些:

Question


I made a tongue-in-cheek comment in another question thread calling PHP a terrible language and it got down-voted like crazy. Apparently there are lots of people here who love PHP.

我在另一个问题上做了个半开玩笑的评论,说PHP是一种糟糕的语言,它被疯狂地否决了。显然这里有很多人喜欢PHP。

So I'm genuinely curious. What am I missing? What makes PHP a good language?

所以我真的很好奇。我缺少什么?是什么让PHP成为一种好语言?

Here are my reasons for disliking it:

以下是我不喜欢它的原因:

  • PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.

    PHP内建函数和库函数的命名不一致。可预测的命名模式在任何设计中都很重要。

  • PHP has inconsistent parameter ordering of built-in functions, eg array_map vs. array_filter which is annoying in the simple cases and raises all sorts of unexpected behaviour or worse.

    PHP内建函数的参数排序不一致,比如array_map和array_filter,这在简单的情况下很烦人,会引起各种意想不到的行为,甚至更糟。

  • The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions. This created a nightmare for anyone doing, say, function callbacks.

    PHP开发人员经常不赞成使用内置函数和低级功能。一个很好的例子是当它们不赞成函数的引用传递时。这对任何执行函数回调的人来说都是一场噩梦。

  • A lack of consideration in redesign. The above deprecation eliminated the ability to, in many cases, provide default keyword values for functions. They fixed this in PHP 5, but they deprecated the pass-by-reference in PHP 4!

    重新设计时缺乏考虑。上面的弃用消除了在许多情况下为函数提供默认关键字值的能力。他们在PHP 5中修复了这个问题,但是他们不赞成PHP 4中的pass-by引用!

  • Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!

    名称空间执行不力(以前根本没有名称空间)。现在有了名称空间,我们用什么作为删除引用字符?反斜杠!通用的转义字符,甚至在PHP中也是如此!

  • Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.

    范围太广的隐式类型转换会导致错误。我对隐式转换没有问题,比方说,浮点到整数或返回。但是PHP(最后我检查过)会很高兴地尝试将数组转换成整数。

  • Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.

    可怜的递归的性能。递归是用任何语言写东西的重要工具;它可以使复杂的算法简单得多。可怜的支持是不可原谅的。

  • Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.

    函数是不区分大小写。我不知道他们在想什么。编程语言是一种为计算机和代码读者指定行为的方法,没有歧义。大小写不敏感会引起歧义。

  • PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.

    PHP鼓励(实际上需要)处理与表示的耦合。是的,您可以编写不这样做的PHP,但实际上更容易以不正确的方式(从声音设计的角度)编写代码。

  • PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.

    没有缓存,PHP性能就糟糕透顶。是否有人销售用于PHP的商业缓存产品?哦,看,PHP的设计者会这么做。

Worst of all, PHP convinces people that designing web applications is easy. And it does indeed make much of the effort involved much easier. But the fact is, designing a web application that is both secure and efficient is a very difficult task.

最糟糕的是,PHP让人们相信设计web应用程序很容易。而且它确实使所涉及的许多努力变得容易得多。但事实是,设计一个既安全又高效的web应用程序是一项非常困难的任务。

By convincing so many to take up programming, PHP has taught an entire subgroup of programmers bad habits and bad design. It's given them access to capabilities that they lack the understanding to use safely. This has led to PHP's reputation as being insecure.

通过说服如此多的人从事编程,PHP已经教会了整个程序员群体坏习惯和坏设计。它给了他们安全使用所缺乏的能力。这导致了PHP的不安全声誉。

(However, I will readily admit that PHP is no more or less secure than any other web programming language.)

(不过,我很乐意承认PHP并不比任何其他web编程语言更安全。)

What is it that I'm missing about PHP? I'm seeing an organically-grown, poorly-managed mess of a language that's spawning poor programmers.

关于PHP我缺少什么?我看到的是一种有机生长的、管理不善的语言的混乱,它正在催生可怜的程序员。

So convince me otherwise!

所以说服我否则!


Top Rated Answer


I'll take a stab at responding to each of your bullet points

我会尝试着回答你的每一个要点

PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.

PHP内建函数和库函数的命名不一致。可预测的命名模式在任何设计中都很重要。

I both love and hate this topic. Because at its core, this issue is correct. Why are some bi-word function split with an underscore, and some aren't? Why do needle and haystack parameters swap positions in the argument signature sometimes? It's ridiculous. But at the end of the day... does this really matter? My IDE with intellisense and php.net just a browser click away, this is just plain not that big of a deal. Is it a negative against PHP as a language? Yes. Does it hinder my ability to be an effective programmer? No.

我既喜欢又讨厌这个话题。因为这个问题的核心是正确的。为什么有些双字函数用下划线拆分,有些却不是?为什么指针和haystack参数有时会交换参数签名中的位置?这是荒谬的。但最后……这真的重要吗?我的IDE有智能感知和php。net浏览器点击一下,这没什么大不了的。它对PHP作为一种语言有负面影响吗?是的。它是否会妨碍我成为一名有效的程序员的能力?不。

The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions. This created a nightmare for anyone doing, say, function callbacks.

PHP开发人员经常不赞成使用内置函数和低级功能。一个很好的例子是当它们不赞成函数的引用传递时。这对任何执行函数回调的人来说都是一场噩梦。

Personally, I think this is not a good point. Deprecation is necessary to the evolution of a language, especially one that has as much kruft as PHP does. PHP gets a lot of flak for "making it easy to be a bad programmer*" but at the same time, the PHP group also gets in trouble when they try to remove stupid constructs from the language, such as call-time pass-by-reference. Eliminating call-time pass-by-reference was one of the best moves they ever made. There was no easier way for a novice developer to shoot themselves in the foot than with this "feature".

我个人认为这不是一个好的观点。对语言的发展来说,弃用是必要的,尤其是像PHP一样拥有大量kruft的语言。PHP因为“让人很容易成为一个糟糕的程序员*”而受到很多指责,但与此同时,当PHP组试图从语言中删除愚蠢的构造(如调用时传递引用)时,也会遇到麻烦。消除按引用进行的呼叫时间传递是他们所做过的最好的步骤之一。对于新手开发人员来说,没有比使用这个“特性”更容易的方法了。

A lack of consideration in redesign. The above deprecation eliminated the ability to, in many cases, provide default keyword values for functions. They fixed this in PHP 5, but they deprecated the pass-by-reference in PHP 4!

重新设计时缺乏考虑。上面的弃用消除了在许多情况下为函数提供默认关键字值的能力。他们在PHP 5中修复了这个问题,但是他们不赞成PHP 4中的pass-by引用!

I don't think there's a general lack of consideration at all, I think you just got stung by this particular change and have been left with a sour taste in your mouth. Language changes are often known months if not years ahead of time. A migration guide was provided for the move from 4 to 5, and the version differences are documented in the manual. Call-time pass-by-reference was a horrible "feature" and doesn't give the developer any expressive power they can't get by other means. I'm glad it is gone (along with other crap like magic quotes)

我不认为人们普遍缺乏考虑,我认为你只是被这种特殊的变化所刺痛,并留下一个酸的味道在你的嘴里。语言的变化即使不是提前几年,也是几个月。为从4到5的迁移提供了迁移指南,并且在手册中记录了版本差异。调用时间传递引用是一个可怕的“特性”,它没有给开发人员任何其他方式无法获得的表达能力。我很高兴它消失了(还有其他的废话,比如神奇的名言)

Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!

名称空间执行不力(以前根本没有名称空间)。现在有了名称空间,我们用什么作为删除引用字符?反斜杠!通用的转义字符,甚至在PHP中也是如此!

I have mixed feelings about this. Part of me thinks "who cares, character escaping has no meaning outside of a string anyway", and part of me thinks "surely they could use something better". But could they? I don't know, I'm not a developer for the Zend parser. Is it a huge oversight that until 5.3 PHP never had namespaces at all? Yes, absolutely.

我对此有复杂的感觉。我的一部分人认为“谁在乎呢,字符转义在字符串之外没有任何意义”,而我的一部分人认为“他们肯定会用更好的东西”。但他们吗?我不知道,我不是Zend解析器的开发人员。直到5.3 PHP根本没有名称空间,这是一个巨大的疏忽吗?是的,当然。

Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.

范围太广的隐式类型转换会导致错误。我对隐式转换没有问题,比方说,浮点到整数或返回。但是PHP(最后我检查过)会很高兴地尝试将数组转换成整数。

I think it's ok to disagree with how PHP does this, but disagree that it makes the language "bad". But ask me how much I want to sit in this topic and argue about weak vs strong typing. (P.S. I don't, at all) For the record: PHP will issue an E_WARNING level error when the type of an argument matters and cannot by solved by coercion.

我认为不同意PHP是如何做到这一点的,但不同意它让语言变得“糟糕”。但是,问问我,我有多想坐在这个话题上讨论弱打字和强打字。(顺便说一句,我一点也不知道)对于记录:当一个参数的类型有问题时,PHP会发出一个E_WARNING级别的错误,并且不能通过强制来解决。

Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.

可怜的递归的性能。递归是用任何语言写东西的重要工具;它可以使复杂的算法简单得多。可怜的支持是不可原谅的。

PHP is a DSL for the web. I've been doing it full-time for 8 years and have maybe used recursion 4 or 5 times, usually for some type of annoying directory or XML traversal. It's just not a pattern that is needed for web development that often. I'm not excusing the slow performance, but this is an academic issue far more than it is a production issue. If you need really powerful recursive performance, PHP is already the wrong language for you.

PHP是一种用于web的DSL。我已经全职使用它8年了,可能使用了4到5次递归,通常用于某些烦人的目录或XML遍历。这并不是web开发经常需要的模式。我并不是在为缓慢的表现辩解,但这是一个学术问题,而不是一个生产问题。如果您需要非常强大的递归性能,PHP对您来说已经是错误的语言了。

Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.

函数是不区分大小写。我不知道他们在想什么。编程语言是一种为计算机和代码读者指定行为的方法,没有歧义。大小写不敏感会引起歧义。

I totally 100% agree with this.

我百分之百的同意。

PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.

PHP鼓励(实际上需要)处理与表示的耦合。是的,您可以编写不这样做的PHP,但实际上更容易以不正确的方式(从声音设计的角度)编写代码。

*Hmmm, this topic sounds desperately familiar...

这个话题听起来非常熟悉……

But seriously, I find it remarkable that people will complain about a language that will absolutely 100% let you implement any output system you want (the sheer volume and style of PHP templating systems alone speaks to this) - OR - skip all that overhead and just output directly. This does not make PHP bad at all. It's part of what makes PHP good.

但认真地说,我发现值得注意的是,人们会抱怨一种完全允许您实现任何您想要的输出系统的语言(仅PHP模板系统的庞大容量和风格就说明了这一点)——或者——跳过所有这些开销,直接输出。这并不会使PHP变得糟糕。它是PHP的一部分。

PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.

没有缓存,PHP性能就糟糕透顶。是否有人销售用于PHP的商业缓存产品?哦,看,PHP的设计者会这么做。

Do you mean bytecode caching (like an accelerator), or output caching?

您是指字节码缓存(如加速器)还是输出缓存?

If the former, then I don't really know how much I care about this topic. Accelerators are free and easy to run. We could argue about why it isn't part of the language but in the end, I don't think it matters much.

如果是前者,我真的不知道我有多在乎这个话题。加速器是免费和容易运行。我们可以争论为什么它不是语言的一部分,但最后,我不认为它很重要。

If you are talking about output caching then I don't know what to say to you. ANY web project with significant traffic needs caching (seed podcast #27, for example). This is not a PHP-specific issue at all.

如果您正在讨论输出缓存,那么我不知道该对您说什么。任何具有重要流量的web项目都需要缓存(例如,种子播客#27)。这根本不是php特有的问题。

In summary, I think you consider PHP a "bad" language in a very academic fashion. And in your previous post you were probably voted down by people like me who use PHP to "get things done".

总之,我认为您认为PHP是一种非常学术的语言。在你之前的文章中,你可能被像我这样使用PHP来“完成任务”的人否决了。


Second Top Rated Answer


All your criticisms (and some more) are valid. You are allowed and even expected to hate PHP.

你所有的批评(还有更多的批评)都是正确的。您可以甚至期望讨厌PHP。

But, then again, it has some benefits:

但是,它也有一些好处:

  • Ubiquitous
  • 无处不在的
  • Fast (especially using opcode caches)
  • 快速(特别是使用操作码缓存)
  • Huge community (and great documentation)
  • 庞大的社区(和优秀的文档)
  • Works
  • 作品

Finally, you can overcome many if not all the downsides by writing good code you'd write in any other language. You can write solid, secure and good smelling code in PHP, which many times will run faster and be easier to host and to scale than many alternatives.

最后,您可以通过编写用任何其他语言编写的好代码来克服许多(如果不是所有的缺点的话)。您可以在PHP中编写可靠、安全且具有良好气味的代码,与许多替代方法相比,这些代码的运行速度更快、更容易托管和扩展。


Third Top Rated Answer


What is it that I'm missing about PHP? I'm seeing an organically-grown, poorly-managed mess of a language that's spawning poor programmers.

关于PHP我缺少什么?我看到的是一种有机生长的、管理不善的语言的混乱,它正在催生可怜的程序员。

Simple. The fact that poor programmers get very defensive about their language. ;) PHP is easy to learn, much easier than the alternatives, and once you've learned it, it's not exactly obvious 1) what's wrong with PHP, 2) how the alternatives are better, and 3) how to switch to, and learn, one of the alternatives.

简单。糟糕的程序员对他们的语言非常抵触。,)PHP很容易学,比其他选项容易得多,一旦你学过了,就会发现1)PHP有什么问题,2)替代方案如何更好,3)如何切换到其中一个替代方案,并从中学习。

And perhaps the fact that, well, what alternatives do people have? ASP? That has plenty of problems on its own, from being unable to run on the majority of webservers (Apache), to some ridiculous and overengineered design choices on its own (webforms? Viewstate? AJAX where your asynchronous" requests are intercepted and run sequentially?) Ruby on Rails? Well, perhaps, except how many webservers support it again? It's not exactly easily approachable at the moment. And it's slow. So perhaps PHP's "strength" is really that no good alternative exists. At least this is why I stay away from all web programming when at all possible. PHP sucks, and I'm not too keen on any of the alternatives either.

也许事实上,人们有什么选择呢?ASP吗?这本身就有很多问题,从不能在大多数web服务器(Apache)上运行,到一些荒唐的、设计过度的选择(webforms?视图状态?在AJAX中,您的异步“请求被拦截并按顺序运行?)Ruby on Rails吗?嗯,也许,除了有多少网络服务器支持它?目前还不太容易接近。这是缓慢的。因此,也许PHP的“优势”实际上并不存在好的替代方案。至少这就是为什么我尽可能远离所有的web编程。PHP很糟糕,我也不太喜欢任何替代方案。

PHP has so many fundamental problems that it's not even funny. From the lack of unicode support, to the many implicit type conversions which often lead to unexpected security holes, to the complete mixing of presentation and... everything else, or to the default database module which doesn't (last I checked) use parametrized queries. We're talking about a language made for two things, database access and generating HTML, and which is terrible at both.

PHP有很多基本的问题,这一点都不好笑。从缺乏unicode支持,到许多隐式类型转换,常常导致意外的安全漏洞,到完整的表示和……其他的东西,或者默认的数据库模块(最后我检查过)没有使用参数化查询。我们说的是一种语言,它有两种功能:数据库访问和生成HTML,这两种语言都很糟糕。

It's just a nasty mess, a language designed by people who aren't qualified, or able, to design a language. ;)

这是一种令人讨厌的混乱,一种由不具备设计语言能力的人设计的语言。,)


#5


4  

For me the worst PHP sin is coupling of presentation with business logic. It's not that you can't write it in a better way, but it doesn't encourage you to, and if anything it encourages you not to.

对我来说,PHP最大的缺点是表示与业务逻辑的耦合。这并不是说你不能把它写得更好,而是它没有鼓励你这样做,如果有的话,它鼓励你不要这样做。

A large number of security vulnerabilities are associated with PHP sites, too. I can't prove it is disproportionate (after all a lot of sites are written in PHP), but I suspect it is. If I'm right, then since security vulnerabilities are a class of bug, I suspect PHP sites tend to be more buggy on the whole also.

许多安全漏洞也与PHP站点相关。我无法证明它是不相称的(毕竟很多网站都是用PHP编写的),但我怀疑它是不相称的。如果我是对的,那么既然安全漏洞是一类bug,那么我怀疑PHP站点在整体上也会更加糟糕。

(I don't think that pointing at a few large sites and saying they managed to do it in PHP is any argument against this, by the way. It's a bit like saying that cigarettes don't cause cancer because your next door neighbour smoked and lived to be 100.)

(顺便说一句,我不认为指向几个大型网站并说他们在PHP中成功地做到了这一点是任何反对这一点的理由。这有点像说香烟不会致癌,因为你的邻居吸烟,活到100岁。

#6


2  

Check out this similar question - Can PHP handle enterprise level sites as well as Java

看看这个类似的问题——PHP可以处理企业级站点,也可以处理Java

Recapping - Facebook, Wikipedia, Yahoo.com, Digg, Flickr and many other giant sites are running on PHP. If you ever come close to making something of that caliber, you can still rest assured you can get there with PHP.

Facebook、*、Yahoo.com、Digg、Flickr和许多其他大型网站都在使用PHP。如果您曾经接近实现这种水平,您仍然可以放心地使用PHP实现。

How maintainable, extendable, reliable, secure and performant your applications will be is entirely up to you and is language-agnostic. In favor of PHP though, it has very convenient tools for building web applications.

应用程序的可维护性、可扩展性、可靠性、安全性和性能将完全取决于您,并且与语言无关。不过,支持PHP的是,它有非常方便的工具来构建web应用程序。

#7


2  

For me, and talking about large or even huge projects, it (primarily) boils down to one word: Dependencies.

对我来说,谈到大型甚至是大型项目,它(主要)可以归结为一个词:依赖。

The problem with a scripting language is like in every thing in the world: The greatest advantage is the greatest disadvantage at the same time.

脚本语言的问题与世界上的任何事物一样:最大的优点同时也是最大的缺点。

The greatest advantage is to code free and fast. Just write a script and it will server it's purpose. No verbosity needed, simply code.

最大的优势是代码*和快速。只要写一个脚本,它就会实现它的目的。不需要冗长,只需编写代码。

The greatest disadvantage is, in a way, to check if this script is not disturbing other scripts. Or better: Change an old script others are relying on. Are you sure that all dependencies do work out as you desired?

最大的缺点是,在某种程度上,检查这个脚本是否没有干扰其他脚本。或者更好:改变别人依赖的旧剧本。您确定所有依赖项都按照您的要求工作吗?

This is not true for "normal" web page generation, whatever normal means here. But we have a product relying on some 500k lines of source code, with customizations for clients consisting of an additional 100k lines of code, too. And I am deadly glad that a compiler checks all dependencies and warns/errors me in case I did something wrong (like, speaking lowest level here, misstyping a variable or method call).

对于“正常”的web页面生成来说,这是不正确的,无论在这里是什么正常的方式。但我们的产品依赖于大约500k行源代码,客户端定制也包括额外的100k行代码。我非常高兴编译器检查所有依赖项并警告/出错,以防我做错了什么事情(比如,这里说的是最低级别,错误地设置变量或方法调用)。

I think this and the fact that other languages provide more simple-to-use "enterprisy" features by their nature (i.e. application servers for "bank usages") boils it down why many do not see PHP in large (or better: huge) projects.

我认为这一点,以及其他语言提供了更容易使用的“企业”特性(即“银行使用的应用服务器”)这一事实,可以归结为为什么许多人在大型(或更好的:大型)项目中看不到PHP。

#8


0  

Our company runs several large-ish web sites using PHP, and have had no problems that were related to the language.

我们公司使用PHP运行了几个大型web站点,并且没有遇到与语言相关的问题。

#9


0  

These are all good answers.

这些都是很好的答案。

I was a newbie. I've only been coding for 5 years but I directly support and manage 85 small to large websites and I'll tell you what, the potential to get sued by having a website down for a day will contribute a lot to your desire to learn how to and make better code.

我是一个新手。我只被编码为5年但我直接支持和管理85家小型到大型网站,我告诉你,可能被起诉通过一个网站一天下来会贡献很多你想学习如何更好的代码。

It's nice to hear established developers share their thoughts on this matter. I don't think PHP is the best, but it seems my investment in "best practices" is well served.

很高兴听到有开发的开发人员分享他们对这个问题的想法。我不认为PHP是最好的,但似乎我对“最佳实践”的投资得到了很好的服务。

Thanks everyone!

谢谢大家!

#10


0  

There's something about the construction of the PHP language that is not good enough for me. For example, the name of the functions. It is a non best practice use a several ways to name a function in one language. The mixture between underscores (function_name), words stick together (functionname), etc.I mean, this is really a mess. There are too many functions that are very similar or do the same things, but their names are so confusing. This is not characteristic of a good programming language.

PHP语言的构造对我来说还不够好。例如,函数的名称。使用多种方法在一种语言中命名函数不是最佳实践。下划线(function_name)和单词(functionname)之间的混合。我的意思是,这真是一团糟。有太多的函数非常相似或做相同的事情,但是它们的名字是如此令人困惑。这不是好的编程语言的特点。

In large deployments, the language must be enough easy and specific to write. Something that PHP omits like the declaration of variable types, become very difficult to understand and deal with later.

在大型部署中,语言必须足够简单和特定于编写。PHP省略了一些类似于变量类型声明的东西,以后很难理解和处理。

Other point is the constant addition of features and canceling of some other. It supposes that the addition of OOP in PHP 5 gonna make the things easier for programmers, but what about the considerations of back compatibility?

另一点是特征的不断增加和其他特征的抵消。它假设在PHP 5中添加OOP会使程序员的工作变得更容易,但是对于向后兼容性的考虑呢?

The principal reason that this programming language is like it is, is due to its origins: Personal Home Page. It was not designed for large deployments.

这种编程语言之所以如此,主要是因为它的起源:个人主页。它不是为大型部署而设计的。

I know that there are great efforts to make this language an enterprise-weight language, and personally, I'm waiting for a good enough open source server-side programming language; but until this day comes, it's gonna run a lot of water under the bridge.

我知道要使这种语言成为一种企业级的语言需要付出巨大的努力,就我个人而言,我正在等待一种足够好的开源服务器端编程语言;但在这一天到来之前,桥下会有很多水。

#11


0  

See: http://www.ukuug.org/events/linux2002/papers/html/php/

参见:http://www.ukuug.org/events/linux2002/papers/html/php/