5

PHP 8.2 預計要將一些字串內指定變數的方法標為 Deprecated,在 9.0 移除

 2 years ago
source link: https://blog.gslin.org/archives/2022/05/06/10692/php-8-2-%e9%a0%90%e8%a8%88%e8%a6%81%e5%b0%87%e4%b8%80%e4%ba%9b%e5%ad%97%e4%b8%b2%e5%85%a7%e6%8c%87%e5%ae%9a%e8%ae%8a%e6%95%b8%e7%9a%84%e6%96%b9%e6%b3%95%e6%a8%99%e7%82%ba-deprecated%ef%bc%8c%e5%9c%a8/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

PHP 8.2 預計要將一些字串內指定變數的方法標為 Deprecated,在 9.0 移除

Twitter 上看到這個蠻大的改變:

New #PHP Implemented PHP 8.2 RFC: Deprecate ${} string interpolation https://t.co/KDop21MTiV

— PHP RFC Bot (@PHPRFCBot) May 5, 2022

裡面的連結是「PHP RFC: Deprecate ${} string interpolation」,在文件中提到了 PHP 語言支援的四種字串內指定變數的方式:

  1. Directly embedding variables (“$foo”)
  2. Braces outside the variable (“{$foo}”)
  3. Braces after the dollar sign (“${foo}”)
  4. Variable variables (“${expr}”, equivalent to (string) ${expr})

提案在 PHP 8.2 裡將 3 與 4 兩種方式標為 deprecated,並且在 PHP 9.0 移除,目前看起來是 31:1 通過了...

Related

PHP 的 Unquoted Strings 將在 PHP 8 被移除

Twitter 上看到 PHP 的 unquoted string 被視為字串的功能將被移除:「PHP RFC: Deprecate and Remove Bareword (Unquoted) Strings」。 常見的情境是 $_GET[bar] 這樣的用法被視為與 $_GET["bar"] 相同... 超奇怪的功能,而現在這個功能已經投票通過,將會在 7.2 被列為 deprecated,到 8 就會拿掉。 這個功能本來是標示 E_NOTICE,但比較特別的是,雖然是列為 deprecated,PHP 7.2 預定會標示為 E_WARNING 而不是 E_DEPRECATED。主要是這次的兩個目標互相衝突 (可以參考原文),取比較有效的那個 (因為 PHP 8 就不會有這個問題了,所以 PHP 7.2 的過渡期以比較容易提醒使用者的那個為主)。 投票是 100% 通過 (41/41)。

March 24, 2017

In "Computer"

PHP 裡的暫存變數

在 Perl 裡我們常用 $_ 當作變數 (很多情況下常常被拿來用,像是 foreach (@array) 內的變數名稱),所以就有人想到在 PHP 裡「模擬」這樣的行為:Perl like temporary variables in PHP。 文章內提到,在 PHP 內 ${0} 是合法的變數,變數名稱就是 0。以此當作暫存變數,寫起來會比 $foo、$bar,或是 $tmp 舒服很多?

January 3, 2008

In "Computer"

PHP 數字與字串比較的提案

在「Links: February 2019」這邊看到 PHP 社群的提案,想要改善數字與字串比較的結果:「PHP RFC: Saner string to number comparisons」。 他給了一個經典的範例: $validValues = ["foo", "bar", "baz"]; $value = 0; var_dump(in_array($value, $validValues)); // bool(true) WTF??? 原因是 in_array() 是 == 而非 ===,所以就噴了... 而提案我看了還是覺得不行啊,看看會怎麼改吧 :o

March 3, 2019

In "Computer"

a611ee8db44c8d03a20edf0bf5a71d80?s=49&d=identicon&r=gAuthor Gea-Suan LinPosted on May 6, 2022Categories Computer, Murmuring, ProgrammingTags deprecated, heredoc, interpolation, language, php, programming, proposal, rfc, string, variable

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

Notify me of follow-up comments by email.

Notify me of new posts by email.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Learn More)

Post navigation


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK