rfc:binary_string_deprecation

PHP RFC: Binary String Deprecation

Introduction

In version 5.2.1, the b prefix and the (binary) cast were introduced for forward compatibility with the PHP-6 project. However, that project never came to be and no one can tell if it will ever be the chosen approach in a possible future attempt to implement binary strings. Yet, these are still accepted by the language scanner although ignored from then on.

Proposal

This RFC aims to deprecate the prefix as it produces no effect on the string literal and the binary cast because it is the same as casting to string.

The proposed implementation consists in throwing a E_DEPRECATED during compilation when the prefix or the cast are used. At a later major version of PHP, the support for these should be removed.

With the implementation of this RFC, the following code:

<?php
 
echo b'Goodbye, world!' . PHP_EOL;
echo (binary)'<- Equivalent to (string)' . PHP_EOL;

Executed on an environment with the error level including E_DEPRECATED will produce:

Deprecated: The usage of the 'b' prefix is deprecated in ... on line 3

Deprecated: The usage of the binary cast is deprecated in ... on line 4
Goodbye, world!
<- Equivalent to (string)

Furthermore, tests and test iterations specifically intended for binary strings are also removed as they aim at a functionality that doesn't exist.

Finally, this RFC also includes a patch for the documentation to remove the reference to this cast in the Type Juggling page and another for the language specification.

Backward Incompatible Changes

Scripts where the prefix or the cast are used will now throw a E_DEPRECATED notice during compilation. Once the deprecation phase is over and the prefix and cast are removed, these scripts will stop compiling.

Proposed PHP Version(s)

The proposed target version is the next PHP-7.x

RFC Impact

To Existing Extensions

To PHAR

This deprecation and subsequent removal may have a greater impact given that PHAR archives using the default stub and generated in a version of PHP prior to 7.1 include (binary) casts.

Future Scope

In the next PHP major version the deprecation phase should end and the prefix and cast should be removed.

Proposed Voting Choices

This RFC requires a 2/3 majority.

Voting starts on 2017-02-03 13:00 UTC and closes on 2017-02-20 20:00 UTC.

Binary String Deprecation
Real name Yes No
ajf (ajf)  
bishop (bishop)  
bwoebi (bwoebi)  
danack (danack)  
daverandom (daverandom)  
davey (davey)  
eliw (eliw)  
galvao (galvao)  
hywan (hywan)  
joey (joey)  
kelunik (kelunik)  
kguest (kguest)  
krakjoe (krakjoe)  
leigh (leigh)  
lstrojny (lstrojny)  
marcio (marcio)  
mariano (mariano)  
mbeccati (mbeccati)  
nikic (nikic)  
ocramius (ocramius)  
peehaa (peehaa)  
pollita (pollita)  
salathe (salathe)  
sammyk (sammyk)  
sebastian (sebastian)  
stas (stas)  
svpernova09 (svpernova09)  
thekid (thekid)  
tpunt (tpunt)  
trowski (trowski)  
yunosh (yunosh)  
zeev (zeev)  
Final result: 19 13
This poll has been closed.

Patches and Tests

This RFC is implemented by the following patches:

References

This deprecation is also proposed in PHP RFC: Deprecations for PHP 7.2. The reason for a separate RFC is the impact on the PHAR extension.

rfc/binary_string_deprecation.txt · Last modified: 2017/09/22 13:28 (external edit)