mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Don't implement Stringable on traits
Traits do not support interfaces, so we should not implement Stringable on them. Also check the __toString() return type in the same way other magic methods do, otherwise we would now miss the check in the trait case.
This commit is contained in:
parent
7e67366a9b
commit
d478ae73b1
6 changed files with 25 additions and 10 deletions
|
@ -2487,7 +2487,8 @@ ZEND_API zend_result zend_do_link_class(zend_class_entry *ce, zend_string *lc_pa
|
|||
|
||||
/* Normally Stringable is added during compilation. However, if it is imported from a trait,
|
||||
* we need to explicilty add the interface here. */
|
||||
if (ce->__tostring && !zend_class_implements_interface(ce, zend_ce_stringable)) {
|
||||
if (ce->__tostring && !(ce->ce_flags & ZEND_ACC_TRAIT)
|
||||
&& !zend_class_implements_interface(ce, zend_ce_stringable)) {
|
||||
ZEND_ASSERT(ce->__tostring->common.fn_flags & ZEND_ACC_TRAIT_CLONE);
|
||||
ce->ce_flags |= ZEND_ACC_RESOLVED_INTERFACES;
|
||||
ce->num_interfaces++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue