Bug #77488 [Com]: __toString in a trait

From: Date: Fri, 18 Jan 2019 23:59:12 +0000
Subject: Bug #77488 [Com]: __toString in a trait
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219076@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77488&edit=1 ID: 77488 Comment by: danack@php.net Reported by: alywena at gmail dot com Summary: __toString in a trait Status: Open Type: Bug Package: Scripting Engine problem Operating System: Windows 10 PHP Version: 7.3Git-2019-01-18 (Git) Block user comment: N Private report: N New Comment: Are you seeing this on any released version, or only against master? Previous Comments: ------------------------------------------------------------------------ [2019-01-18 23:52:19] alywena at gmail dot com Description: ------------ If an object has a __toString() method define in a trait, the object could not be converted to string. Test script: --------------- trait ToString { abstract public function toString(): string; public function __toString(): string { return $this->toString(); } } class Foo { use ToString; public function toString() { return 'bar'; } } $foo = new Foo(); echo $foo; Expected result: ---------------- 'bar' Actual result: -------------- Object of class Foo could not be converted to string ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77488&edit=1

« previous php.bugs (#219076) next »