php / php/php-src

${} is deprecated without documenting new behaviour in PHP 9.0

Đang mở
#8,501 5 bình luận 2 reaction 1 người được giao Xem trên GitHub

@iluuu1994 đang làm issue này rồi.

Từ ngày 6/5/2022.

Bug Category: Engine Status: Verified
Ngôn ngữ chính
C
Star
40.4k
Fork
8.1k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

Description

According to this accepted RFC, and according to https://github.com/php/php-src/pull/8212 , the following code is deprecated in PHP 8.2, and is scheduled for removal in PHP 9.0:

<?php
var_dump("${foo}");
// Deprecated: Using ${} in strings is deprecated
 
var_dump("${(foo)}");
// Deprecated: Using ${} (variable variables) in strings is deprecated

However, this RFC does not document what the behaviour will be in PHP 9.0. Will it raise a syntax error? Or will treat it like a plain string literal?

<?php
var_dump("${foo}");
// In PHP 9.0, will this raise a syntax error? Or will it be equal to '${foo}' ?
 
var_dump("${(foo)}");
// In PHP 9.0, will this raise a syntax error? Or will it be equal to '${(foo)}' ?

I think this is important to consider this question to help those migrating their codebase to PHP 9.0 in the future, and to alert those who may not realise this code may need modification. I personally propose that this raise a syntax error in PHP 9.0. Later versions can allow this syntax again, if needed, with the new behaviour of acting like a normal string literal with no special behaviour. This means that the migration path would be:

  1. Old syntax is supported
  2. Old syntax raises a deprecation warning, but works as before (PHP 8.2)
  3. Old syntax raises a syntax error (PHP 9.0)
  4. In the future, the old syntax may be allowed again, with the new behaviour
PHP Version

PHP 8.2

Operating System

No response

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.