Improve array to string conversion View as Markdown

Withdrawn
Authors
François Laupretre, francois@tekwire.net
Version
2.1
Source
wiki.php.net/rfc/array-to-string

Vote

array-to-string closed
Yes
34
No
10
44 voters
aharvey Yes 2015-03-02 20:47
ben Yes 2015-03-02 17:01
brandon Yes 2015-03-03 13:54
bwoebi Yes 2015-03-01 23:29
danack Yes 2015-02-24 18:37
datibbaw No 2015-03-02 22:11
diegopires Yes 2015-02-25 14:33
duodraco Yes 2015-03-03 20:40
francois Yes 2015-02-24 04:32
frozenfire Yes 2015-02-24 02:59
guilhermeblanco Yes 2015-02-25 14:29
gwynne Yes 2015-03-01 21:19
hywan Yes 2015-03-06 11:08
ircmaxell Yes 2015-02-24 02:58
jedibc Yes 2015-02-27 12:12
jpauli No 2015-02-25 09:08
jwage Yes 2015-03-01 15:27
kalle Yes 2015-02-23 16:52
kinncj Yes 2015-02-26 15:48
krakjoe Yes 2015-02-25 06:21
laruence No 2015-02-25 11:15
lcobucci Yes 2015-02-25 18:54
leigh Yes 2015-02-24 19:29
lstrojny Yes 2015-03-02 12:51
mbeccati No 2015-02-25 12:10
mfischer Yes 2015-02-24 11:44
mike No 2015-03-06 16:07
mrook Yes 2015-02-26 20:27
nikic No 2015-03-02 20:46
olemarkus Yes 2015-02-24 09:44
patrickallaert No 2015-03-02 12:39
pauloelr Yes 2015-02-24 20:53
pollita Yes 2015-02-26 19:31
rasmus No 2015-02-25 14:59
rdohms Yes 2015-02-24 10:52
santiagolizardo Yes 2015-02-25 11:57
sobak No 2015-03-03 04:29
stas Yes 2015-03-06 00:24
till Yes 2015-02-27 15:25
treffynnon Yes 2015-02-25 14:55
tyrael No 2015-03-06 09:39
yohgaki Yes 2015-02-25 07:55
yunosh Yes 2015-02-24 07:46
zeev Yes 2015-03-02 14:23

Discussions on the mailing list

[RFC] Improve array to string conversion
by F & N Laupretre · 5 messages
[RFC][VOTE] Improve array to string conversion
by Patrick ALLAERT · 2 messages
Question/comment about the Array to String conversion RFC
by Zeev Suraski · 22 messages
Allow throwing from __toString()
by Nikita Popov · 6 messages

RFC text

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

This RFC is withdrawn because discussion shows that the subject is far from mature and potential side effects require more discussions. It will probably be revived in the future but potential BC breaks reserve such changes for a major release.

Introduction

Currently, array to string zval conversion raises an E_NOTICE and returns a string containing 'Array'.

This RFC considers this behavior as non-optimal and proposes improvements.

Proposal

As seen above, zval conversion from array to string, implicit or explicit, gives E_NOTICE and 'Array'.

We consider this as no more than a temporary half-backed solution : we raise a low-level error and we return a useless string.

Now, the release of a new major version is the occasion to make a definitve decision.

Note: the RFC originally proposed, either to fully support the feature, or to deprecate it.
Following discussion, it was decided to only propose the option of deprecating it.
So the other option was removed, and can be consulted via older versions of the RFC.

1st alternative: deprecate

Here, we consider that array-to-string conversion was never actively supported nor encouraged, that, it most cases, its only effect is hiding bugs, and that it is time to disable it definitely.

Another argument is that there never was an agreement on the 'standard' way to convert an array to a string.

So, we propose that Array-to-string conversions are considered exactly the same as object-to-string with no '__toString' method: any conversion attempt generates an E_RECOVERABLE_ERROR. Then, if the program is still alive, the conversion returns 'Array' as before. The E_NOTICE message is suppressed. No more worries about hiding bugs with this logic, as masking such an error level is a strong user decision, definitely not the same as disabling E_NOTICE.

We could go through a migration phase using E_DEPRECATED, but we consider that, since an E_NOTICE is currently generated, it may be considered as a deprecation notice, and we can directly switch to E_RECOVERABLE_ERROR.

Another argument is that, while this one should not be very problematic, it is always better to introduce a BC break in a major version.

If 5.7 is revived, it will contain an interim version, with E_NOTICE replaced by E_DEPRECATED.

2nd alternative: full support

Removed

Backward Incompatible Changes

The potential BC breaks are important because a lot of PHP code runs in E_NOTICE-disabled environments and the 'Array' return value, while probably invalid, may easily go unnoticed.

In balance of this, we can consider that raising the error level in environments where E_NOTICE messages are disabled, will generally help discovering bugs that had remained unnoticed because the error level was hidden.

Actually, during the discussion, the opinions seemed to converge towards the position that discovering undetected bugs is probably more important than potential BC breaks.

Proposed PHP Version(s)

7.0

RFC Impact

Touches every explicit or implicit array-to-string conversion, whether called from extensions or in PHP code.

Open Issues

None

Unaffected PHP Functionality

No other type conversion is impacted.

Future Scope

None

Proposed Voting Choices

Basic Yes/No : Yes to replace E_NOTICE with E_RECOVERABLE_ERROR, No for no change.

Vote: array-to-string — Yes: 34 · No: 10 (closed)

Voting will close March 6th, 00:00 (UTC).

Required majority : 2/3 of voters.

Patches and Tests

Patch provided, fixing existing tests is under way.

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged to
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature

References

PR : https://github.com/php/php-src/pull/991

32 tests are broken by this change. The coresponding fixes are under way and not included in the PR.

Rejected Features

(Keep this updated with features that were discussed on the mail lists)