Table of Contents
回复内容:
请注意
PHP是世界上最好的语言,没有之一
Home Backend Development PHP Tutorial 为什么那么多人吐糟PHP 也没说原因

为什么那么多人吐糟PHP 也没说原因

Jun 06, 2016 pm 08:39 PM
php

为什么那么多人吐糟PHP 也没说原因

这个问题已被关闭,原因:

回复内容:

为什么那么多人吐糟PHP 也没说原因

客观的回答:

1.PHP语言以及环境,与其他主流语言及其环境相比,很差,这是缺点。

2.PHP在互联网发展史上曾经非常辉煌,Web2.0基本上是它的功劳。而且那个年代能赚钱的基本上也都是PHP的,这些是优点。

所以,由于PHP有矛盾如此激烈的缺点与优点,所以才会产生巨大的争议与话题。其他语言由于没有这么激烈的矛盾,所以不会出现这种情况。

我之前写过很久 PHP, 但现在是 PHP 黑,简单说一下原因。

  • 语法设计不合理

    这个诚然有历史原因,但确实是不合理。

    • 命名空间用(\)分隔,简直丧心病狂;对象成员用(->)访问,略显繁琐
    • 函数名不区分大小写,老版本的类名也不区分大小写,而变量名却区分大小写
    • 数组的写法繁琐(array()),直到 5.4 才有简写语法([]
    • 这样function test_array(array $input_array), 可以限制参数的类型,适用于类和数组,却不适用于 intstring
    • unset, echo, empty, list 长得像函数,却不是函数
    • 直到 5.4 才支持 func()[0] 这种写法
    • 大部分内部函数默认不会抛出异常,导致 PHP 中存在两套独立的错误处理机制
  • 很多被弃用的功能仍被广泛使用,新的功能被普及得很慢

    这个是使用者的事情,但情况就是如此。

    在开源软件中更为突出,比如 WordPress 为了尽可能兼容旧的 PHP 版本,没法用上例如匿名函数(5.3), 数组简写语法(5.4) 这种能够大幅改善代码可读性的功能。

    下面是一些被弃用的功能,这些功能大多是设计上存在失误,后来因为可能导致潜在的问题被弃用,但因为网络上互相转载的一些不靠谱教程,所以很多人依然在使用。

    • __autoload
    • mysql_* 系列函数
    • Register Globals
    • Magic Quotes
    • Safe Mode
  • 缺少好用的包管理器和依赖管理方案

    PHP 和 Python, Ruby, Node.js 在使用领域上是有一定重叠的,我们来比较一下包的数量:

    • PHP Composer: 46k
    • Python PyPI: 53k
    • Ruby Gems: 94k
    • Node.js NPM: 116k

    虽然包的数量不代表质量,但是代表了人们是否愿意发布和使用包。

    Composer 在 PHP 中的普及率恐怕不及上面其他三款包管理器,比如作为最火的博客程序 WordPress, 和国内的 Typecho 都没有使用 Composer, 而是直接在源代码中包含所有依赖。

  • 必须为每个请求创建一个单独的进程

    PHP 必须为每个请求创建一个进程(或线程),这导致在高并发的情况下会占用大量内存。

    在 PHP 中很难创建一个资源,并让它可以在全局范围内,可以被所有请求访问到,只能通过外部的数据库或缓存来实现。亦没有办法定义一项任务,独立于其他请求运行,只能通过单独的任务队列来解决。虽然这两个问题并不严重,但无法轻量级地维护全局的状态,算是一个缺憾。

  • PHP 是为 Web 优化的编程语言

    • 可以直接用 $_GET$_POST 访问来自客户端的 GET 和 POST 数据
    • 可以用 <?php ?> 的方式嵌入到 HTML 文件中

    现在大多数 Web 程序,往往都是 MVC 架构,在这种架构下,具有额外语法糖的 PHP 并不会比通用编程语言更好用。

    相反的方面,虽然 PHP 可以用于 Web 之外的场景,但坑实在是多。例如缺少好用的异步流程控制的方案等。

黑某种语言只能说明此人见识少,语言只是工具,适用于不同的场合,不喜欢可以不用。你都不用了怎么有资格黑。

比如有些人说php的shell功能弱,人家php天生就是为web开发设计,你要拿筷子当叉子用,还说人家不好用。

比如说php性能差,殊不知很多.Net和Java的初学者写出来的网站,一堆的性能bug,难道这不是php设计上的优点。

有优点当然也有缺点,关键看你怎么用。黑PHP的人估计是想不明白为啥国内大的互联网公司都用PHP

php上手简单 没什么难度
黑他只是为了显示自己学的语言有多好
黑他才能显得自己水平高
Python c c++ 语言也都有自己不足的地方 你也去黑黑
对php了解一些了你就使劲黑吧

有句话说 程序员应该为自己的行为负责 但是实际上很少有程序员做的到这点 于是有c++ c# java这种强类型语言来约束程序员的行为
php显然缺少这些条条框框 而且php弱类型的实现的却有一些诟病的地方

同意 @我是谁啊2015_73720 的说法,总不能说手机没有单反拍照好用,就说手机设计不合理,人家生来就不是做这件事的,做好本职工作就足够了。

更新换代速度慢是注定的,庞大的用户量不是PHP说升级就能升级的,至少要用户配合。微软这样致力推广Windows的更新,现在还不是一样有不少用人XP的?

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

请注意

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

PHP是世界上最好的语言,没有之一

这种问题以后少问,如果PHP不好,那么怎么还那么多公司用?
PHP不死,这种问题这轮不到你们这些人来评论!

PHP是世界上最好的语言,没有之一

来自知乎的回答

楼上好多 大神啊!!!

自以为是的 大婶。。。

不懂就乱黑。。。笑

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles