Take the State of PHP 2026 Survey →

Binary String Deprecation View as Markdown

Declined
Authors
Pedro Magalhães, mail at pmmaga dot net
Date
2016-12-11
Version
0.2
Source
wiki.php.net/rfc/binary_string_deprecation

Vote

Binary String Deprecation closed
Yes
19
No
13
32 voters
ajf No 2017-02-15 15:19
bishop Yes 2017-02-06 17:22
bwoebi Yes 2017-02-05 10:44
danack Yes 2017-02-13 11:01
daverandom Yes 2017-02-10 13:36
davey No 2017-02-16 23:09
eliw No 2017-02-03 21:07
galvao No 2017-02-07 12:57
hywan No 2017-02-15 22:55
joey No 2017-02-06 22:52
kelunik Yes 2017-02-16 19:34
kguest Yes 2017-02-15 09:52
krakjoe Yes 2017-02-13 10:49
leigh Yes 2017-02-07 17:19
lstrojny Yes 2017-02-20 19:36
marcio Yes 2017-02-15 12:28
mariano Yes 2017-02-10 22:46
mbeccati No 2017-02-16 14:25
nikic Yes 2017-02-03 19:20
ocramius Yes 2017-02-08 11:38
peehaa Yes 2017-02-06 19:46
pollita No 2017-02-06 20:28
salathe No 2017-02-08 19:49
sammyk No 2017-02-06 23:43
sebastian Yes 2017-02-17 06:04
stas No 2017-02-06 19:33
svpernova09 No 2017-02-10 16:31
thekid Yes 2017-02-09 19:57
tpunt Yes 2017-02-13 10:50
trowski Yes 2017-02-08 01:15
yunosh Yes 2017-02-06 10:32
zeev No 2017-02-07 09:23

Discussions on the mailing list

Deprecate b-prefix for strings
by Juliette Reinders Folmer · 7 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:52 UTC

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.

Vote: Binary String Deprecation — Yes: 19 · No: 13 (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.