Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100786 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76685 invoked from network); 27 Sep 2017 12:45:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Sep 2017 12:45:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=marlies.heijkoop@belsimpel.nl; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=marlies.heijkoop@belsimpel.nl; sender-id=pass Received-SPF: pass (pb1.pair.com: domain belsimpel.nl designates 89.188.25.245 as permitted sender) X-PHP-List-Original-Sender: marlies.heijkoop@belsimpel.nl X-Host-Fingerprint: 89.188.25.245 mail.mobielwerkt.nl Received: from [89.188.25.245] ([89.188.25.245:24317] helo=mail.mobielwerkt.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/74-34114-16D9BC95 for ; Wed, 27 Sep 2017 08:45:23 -0400 Received: from S2016-EX-1.ad.mobielwerkt.nl (192.168.1.142) by S2016-EX-2.ad.mobielwerkt.nl (192.168.1.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.669.32; Wed, 27 Sep 2017 14:45:15 +0200 Received: from S2016-EX-1.ad.mobielwerkt.nl ([fe80::f8e7:bc4e:8f41:f596]) by S2016-EX-1.ad.mobielwerkt.nl ([fe80::f8e7:bc4e:8f41:f596%6]) with mapi id 15.01.0669.032; Wed, 27 Sep 2017 14:45:15 +0200 To: "PHP internals (internals@lists.php.net)" Thread-Topic: E_RECOVERABLE_ERROR for object to string conversion Thread-Index: AdM3iryMCfkqQD5DT+uehnuf5CyTkw== Date: Wed, 27 Sep 2017 12:45:15 +0000 Message-ID: <871ffa2fa9174506b227dbd6c6b816b4@belsimpel.nl> Accept-Language: en-US, nl-NL Content-Language: nl-NL X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.192.168.246] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: E_RECOVERABLE_ERROR for object to string conversion From: marlies.heijkoop@belsimpel.nl (Marlies Heijkoop) Hi Internals, I stumbled upon a difference in behavior between PHP >=3D7.0 and HHVM when = it comes to object-to-string conversion for objects not implementing a `__t= oString` which caught me by surprise. It's probably a pretty common scenario, especially for inexperienced PHP de= velopers, 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 w= ill emit an E_RECOVERABLE_ERROR where HHVM throws an Error. See https://3v4l.org/WtJff for a minimal example. HHVM's behavior makes mo= re 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 engin= e' RFC and couldn't find any mention of this specific case so I was wonderi= ng 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 wa= ste of time if there is some good reason for having kept this an E_RECOVERA= BLE_ERROR I'm unaware of. Met vriendelijke groet, =A0 Marlies Heijkoop ----- MobielWerkt BV / Belsimpel.nl =A0 T. +31 (0)50 210 34 04 E. marlies.heijkoop@belsimpel.nl I.=A0https://www.belsimpel.nl =A0 Bezoekadres: Waagstraat 1 9712 JX, Groningen =A0 Postadres: Postbus 3023 9701 DA, Groningen =A0 Op deze e-mail is een disclaimer van toepassing, ga naar=A0www.belsimpel.nl= /disclaimer_email A disclaimer is applicable to this e-mail, please refer t= o=A0www.belsimpel.nl/disclaimer_email