Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100787 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78885 invoked from network); 27 Sep 2017 13:01:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Sep 2017 13:01:25 -0000 Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.15.15 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.15.15 mout.gmx.net Received: from [212.227.15.15] ([212.227.15.15:63408] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DE/D4-34114-321ABC95 for ; Wed, 27 Sep 2017 09:01:24 -0400 Received: from [192.168.2.106] ([79.243.124.218]) by mail.gmx.com (mrgmx002 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MSdz2-1dpX081m2m-00RYUv; Wed, 27 Sep 2017 15:01:20 +0200 To: Marlies Heijkoop , "PHP internals (internals@lists.php.net)" References: <871ffa2fa9174506b227dbd6c6b816b4@belsimpel.nl> Message-ID: Date: Wed, 27 Sep 2017 15:01:22 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <871ffa2fa9174506b227dbd6c6b816b4@belsimpel.nl> Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:qi2RKJNHqQAfA51OX2UPTXKG2ay047rdMiQO8CGSBpWSlq25S/h v0t+RiIWlMy7K7dx5Vw1cgdfXsPF8/2demLCsGmjSj9ujIVHdzqPU3JGhew8d0cG1Ze25GO YtVe2DmxKCIYMDZFP6BNGcldAVwZGUtm1+PE+D9TUbuFlYNIjkTUeew/1+/W8TVKYNcphd6 dXjVz9qyMd4gH6Yj8TFnw== X-UI-Out-Filterresults: notjunk:1;V01:K0:qnsor952Lp8=:8OLx0E6GgK8EwvDspr1lQU osiN/2l0vKiVDVus7oZV+GzduDRVCUAx8asoVsrPwaqU5GOjqvcqT1wpwsyKKSQmhlOjGCCKz E/t4n4h63UNSNYevwaa0/PTcEj6iO4yZ76Fr9W3sMMYNg2vwZbUWLBK/l6+ADvrvIF7IkGAte TBz1gThn6yv0Uq9oyeiuJgHtxwAwOuCi3xnlGwLzOzfKTemLY40dpi2NIqygPcqutpetwDFza DIAi0hGAc8Jo0CpOXG71yfqXHFdaSXSP+LPpvu1YGE49Khzl9Lv523I1Z5JGnDOslZpnyi5fR HI+pIC6YPXFcAzQspW05KVHsq+Sq/Vy53jkmObAR4sM6E+nH8BkCcYJhZgaQVJZrcOJLL4r/O u8ubZOq73X5cxhEy6gFJg3eJZwlKinaT2XqSI34QqQOcyomGIjT79nSIcsWEJBCMN8HL7MD6S YS/F2218NoZfR50f1EdskUrpFC7OdiLg1fKvR30jqAlebiCKYBsTB8WwxiZjpQOS886dFYtnr 1m4HqnMqJHV6eNTXVft7KhmrxVrCUW6a7JQNTcAwPxPC7FENDccm7mWT2/uVCAR8aUYBHGVf+ mIYVuCbOj1CxVrfoxtBcIxi/uQbsGi/+MU4SPKaRaWwjpG1xbRwa34GKJsG2NxwNWMDVBNYn1 5NUizs9XiIk3AVpQFddDNH4fnEjL0lyhAuAyOAlOLXUmEiG1qAj08iCPh10xgOguXwn6J/bvT hYZ1XxQuN6jDX59UWLkvWS/7ASRascd6LK2bhBBJQMFz5W5ehHs9XllRjYPsa99RtGf8FMOJn eCzoYpaDh2ArDuTtNV0icR1Neicso+dspcC7f++KjQMTs9eDHU= Subject: Re: E_RECOVERABLE_ERROR for object to string conversion From: cmbecker69@gmx.de ("Christoph M. Becker") On 27.09.2017 at 14:45, Marlies Heijkoop wrote: > Hi Internals, > > I stumbled upon a difference in behavior between PHP >=7.0 and HHVM when it comes to object-to-string conversion for objects not implementing a `__toString` which caught me by surprise. > > It's probably a pretty common scenario, especially for inexperienced PHP developers, as all it takes is to accidentally name your method `_toString()` or `toString()` rather than `__toString()`. > > When trying to use an object which does not implement a __toString(), PHP will emit an E_RECOVERABLE_ERROR where HHVM throws an Error. > See https://3v4l.org/WtJff for a minimal example. HHVM's behavior makes more sense to me here. > > To me, PHP's behavior is especially unexpected if you consider the behavior in https://3v4l.org/lF7gR where PHP *does* throw a (Type)Error because of the typehint. Note this example works if you change `$a` for an instance of something with a proper `__toString()`-method. > > I searched through the discussions on the original 'Exceptions in the engine' RFC and couldn't find any mention of this specific case so I was wondering if anyone remembers if this was deliberately kept this way? I'm not sure if I have the skill to write a patch, I'm willing to try, but it'd be a waste of time if there is some good reason for having kept this an E_RECOVERABLE_ERROR I'm unaware of. I assume that this is closely related to the fact that PHP can't throw from inside of __toString(), see and . -- Christoph M. Becker