{
  "source_file": "0930",
  "source_platform": "Dev.to",
  "author": "amananandrai",
  "title_listed": "PHP 8 has released!!",
  "keywords": "",
  "domain": "机器学习",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://dev.to/amananandrai/php-8-has-released-k51",
  "publish_date": "2020-11-28",
  "corpus_stage": "",
  "notes": "",
  "id": "706a07397def",
  "collected_at": "2026-10-02T14:02:53",
  "title": "PHP 8 has released!! - DEV Community",
  "body_markdown": "PHP released its new version on 26 November 2020. PHP which is a recursive acronym like GNU stands for\nPHP: Hypertext Preprocessor\n. It is one of the most used backend language in the field of web development. Although now new web development frameworks have arrived like NodeJS, Django, Flask, Laravel, Drupal, etc still PHP is a major player in the back-end market. PHP is a general-purpose scripting language especially suited to web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1994.\nThe PHP development team stated about its new release as:\n\"PHP 8.0 is a major update of the PHP language.\nIt contains many new features and optimizations including named arguments, union types, attributes, constructor property promotion, match expression, nullsafe operator, JIT, and improvements in the type system, error handling, and consistency.\"\nSome of the major changes in the new release are:-\nNamed Arguments\nAttributes\nConstructor Property Promotion\nUnion Types\nMatch Expression\nNullsafe Operator\nConsistent type errors for internal functions\nNew JIT compilation engines\nThe details of some of these changes is given below\nNamed Arguments\nSpecify only required parameters, skipping optional ones.\nArguments are order-independent and self-documented.\n// PHP 7\nhtmlspecialchars\n(\n$string\n,\nENT_COMPAT\n|\nENT_HTML401\n,\n'UTF-8'\n,\nfalse\n);\nEnter fullscreen mode\nExit fullscreen mode\n// PHP 8\nhtmlspecialchars\n(\n$string\n,\ndouble_encode\n:\nfalse\n);\nEnter fullscreen mode\nExit fullscreen mode\nAttributes\nInstead of PHPDoc annotations, you can now use structured metadata with PHP's native syntax.\n// PHP 7\nclass\nPostsController\n{\n/**\n     * @Route(\"/api/posts/{id}\", methods={\"GET\"})\n     */\npublic\nfunction\nget\n(\n$id\n)\n{\n/* ... */\n}\n}\nEnter fullscreen mode\nExit fullscreen mode\n// PHP 8\nclass\nPostsController\n{\n#[Route(\"/api/posts/{id}\", methods: [\"GET\"])]\npublic\nfunction\nget\n(\n$id\n)\n{\n/* ... */\n}\n}\nEnter fullscreen mode\nExit fullscreen mode\nConstructor property promotion\nLess boilerplate code to define and initialize properties.\n//PHP 7\nclass\nPoint\n{\npublic\nfloat\n$x\n;\npublic\nfloat\n$y\n;\npublic\nfloat\n$z\n;\npublic\nfunction\n__construct\n(\nfloat\n$x\n=\n0.0\n,\nfloat\n$y\n=\n0.0\n,\nfloat\n$z\n=\n0.0\n,\n)\n{\n$this\n->\nx\n=\n$x\n;\n$this\n->\ny\n=\n$y\n;\n$this\n->\nz\n=\n$z\n;\n}\n}\nEnter fullscreen mode\nExit fullscreen mode\n// PHP 8\nclass\nPoint\n{\npublic\nfunction\n__construct\n(\npublic\nfloat\n$x\n=\n0.0\n,\npublic\nfloat\n$y\n=\n0.0\n,\npublic\nfloat\n$z\n=\n0.0\n,\n)\n{}\n}\nEnter fullscreen mode\nExit fullscreen mode\nUnion types\nInstead of PHPDoc annotations for a combination of types, you can use native union type declarations that are validated at runtime.\n//PHP 7\nclass\nNumber\n{\n/** @var int|float */\nprivate\n$number\n;\n/**\n   * @param float|int $number\n   */\npublic\nfunction\n__construct\n(\n$number\n)\n{\n$this\n->\nnumber\n=\n$number\n;\n}\n}\nnew\nNumber\n(\n'NaN'\n);\n// Ok\nEnter fullscreen mode\nExit fullscreen mode\n//PHP 8\nclass\nNumber\n{\npublic\nfunction\n__construct\n(\nprivate\nint\n|\nfloat\n$number\n)\n{}\n}\nnew\nNumber\n(\n'NaN'\n);\n// TypeError\nEnter fullscreen mode\nExit fullscreen mode\nMatch Expression\nThe new match is similar to switch and has the following features:\nMatch is an expression, meaning its result can be stored in a variable or returned.\nMatch branches only support single-line expressions and do not need a break; statement.\nMatch does strict comparisons.\n// PHP 7\nswitch\n(\n8.0\n)\n{\ncase\n'8.0'\n:\n$result\n=\n\"Oh no!\"\n;\nbreak\n;\ncase\n8.0\n:\n$result\n=\n\"This is what I expected\"\n;\nbreak\n;\n}\necho\n$result\n;\n//> Oh no!\nEnter fullscreen mode\nExit fullscreen mode\n// PHP 8\necho\nmatch\n(\n8.0\n)\n{\n'8.0'\n=>\n\"Oh no!\"\n,\n8.0\n=>\n\"This is what I expected\"\n,\n};\n//> This is what I expected\nEnter fullscreen mode\nExit fullscreen mode\nNullsafe operator\nInstead of null check conditions, you can now use a chain of calls with the new nullsafe operator. When the evaluation of one element in the chain fails, the execution of the entire chain aborts and the entire chain evaluates to null.\n// PHP 7\n$country\n=\nnull\n;\nif\n(\n$session\n!==\nnull\n)\n{\n$user\n=\n$session\n->\nuser\n;\nif\n(\n$user\n!==\nnull\n)\n{\n$address\n=\n$user\n->\ngetAddress\n();\nif\n(\n$address\n!==\nnull\n)\n{\n$country\n=\n$address\n->\ncountry\n;\n}\n}\n}\nEnter fullscreen mode\nExit fullscreen mode\n//PHP 8\n$country\n=\n$session\n?->\nuser\n?->\ngetAddress\n()\n?->\ncountry\n;\nEnter fullscreen mode\nExit fullscreen mode\nSaner string to number comparisons\nWhen comparing to a numeric string, PHP 8 uses a number comparison. Otherwise, it converts the number to a string and uses a string comparison.\n// PHP 7\n0\n==\n'foobar'\n// true\nEnter fullscreen mode\nExit fullscreen mode\n// PHP 8\n0\n==\n'foobar'\n// false\nEnter fullscreen mode\nExit fullscreen mode\nThese are some of the changes to know about all the changes visit this\nlink\n.",
  "metadata": {
    "title": "PHP 8 has released!! - DEV Community",
    "description": "PHP released its new version on 26 November 2020. PHP which is a recursive acronym like GNU stands fo... Tagged with webdev, php, news.",
    "keywords": "webdev, php, news, software, coding, development, engineering, inclusive, community",
    "author": null,
    "og:type": "article",
    "og:url": "https://dev.to/amananandrai/php-8-has-released-k51",
    "og:title": "PHP 8 has released!!",
    "og:description": "PHP released its new version on 26 November 2020. PHP which is a recursive acronym like GNU stands fo...",
    "og:site_name": "DEV Community",
    "og:image": "https://media2.dev.to/dynamic/image/width=1000,height=500,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fys9dn4szpmqky95hvb4j.jpg",
    "twitter:site": "@thepracticaldev",
    "twitter:creator": "@",
    "twitter:title": "PHP 8 has released!!",
    "twitter:description": "PHP released its new version on 26 November 2020. PHP which is a recursive acronym like GNU stands fo...",
    "twitter:card": "summary_large_image",
    "twitter:widgets:new-embed-design": "on",
    "twitter:image:src": "https://media2.dev.to/dynamic/image/width=1000,height=500,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fys9dn4szpmqky95hvb4j.jpg"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [
    {
      "file": "attachments/706a07397def/code/body-000.txt",
      "chars": 78,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-001.txt",
      "chars": 58,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-002.txt",
      "chars": 144,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-003.txt",
      "chars": 128,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-004.txt",
      "chars": 240,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-005.txt",
      "chars": 144,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-006.txt",
      "chars": 211,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-007.txt",
      "chars": 126,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-008.txt",
      "chars": 164,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-009.txt",
      "chars": 116,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-010.txt",
      "chars": 218,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-011.txt",
      "chars": 61,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-012.txt",
      "chars": 31,
      "language": "text"
    },
    {
      "file": "attachments/706a07397def/code/body-013.txt",
      "chars": 32,
      "language": "text"
    }
  ],
  "images": [],
  "audio": [],
  "videos": [],
  "links": [
    {
      "href": "https://www.php.net/releases/8.0/en.php",
      "label": "link",
      "type": "a"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-14T10:49:23Z",
  "source_url": "https://dev.to/amananandrai/php-8-has-released-k51",
  "papers": [],
  "actual_video_files": [],
  "body_chars": 4721,
  "expected_body_images": 0,
  "discovery_status": "ok",
  "delivery_status": "ok",
  "missing_reason": "",
  "raw_html": "attachments/706a07397def/pages/source.html",
  "local_html": "attachments/706a07397def/pages/article.html",
  "body_base_path": "attachments/706a07397def/pages/",
  "body_markdown_path": "attachments/706a07397def/pages/article.md"
}