mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00

Requiring all internal classes (including those from 3rd-party extensions) to implement Stringable if they provide __toString() is too error prone. Case in point, our _ZendTestClass test class was not doing so, resulting in preloading test failures after recent changes. Instead we automatically implement Stringable, the same as we do for userland classes. We still allow explicit implementations, but ignore them (normally they would result in an error due to duplicate interface implementation). Finally, we need to be careful about not trying to implement Stringable on Stringable itself. In some cases this changes the interface order, in particular the automatic Stringable implementation will now come first.
16 lines
338 B
PHP
16 lines
338 B
PHP
--TEST--
|
|
Stringable should be automatically implemented for internal classes
|
|
--SKIPIF--
|
|
<?php
|
|
if (!extension_loaded('zend-test')) die('skip');
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
|
|
// _ZendTestClass defines __toString() but does not explicitly implement Stringable.
|
|
$obj = new _ZendTestClass;
|
|
var_dump($obj instanceof Stringable);
|
|
|
|
?>
|
|
--EXPECT--
|
|
bool(true)
|