php-src/Zend/tests/stringable_internal_class.phpt
Nikita Popov b302bfabe7 Implement Stringable automatically for internal classes
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.
2021-11-05 10:22:04 +01:00

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)