Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86862 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78931 invoked from network); 25 Jun 2015 12:52:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jun 2015 12:52:47 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.48 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 74.125.82.48 mail-wg0-f48.google.com Received: from [74.125.82.48] ([74.125.82.48:34885] helo=mail-wg0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B5/60-09106-D99FB855 for ; Thu, 25 Jun 2015 08:52:46 -0400 Received: by wgbhy7 with SMTP id hy7so61726194wgb.2 for ; Thu, 25 Jun 2015 05:52:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=mfeBlxi/si7MIX1CK7+kMJN8YZVjQdzmWOt4qvIOGFc=; b=a5G7pIyXrmAbDFVqcQhsutVDQjum+ZhdspgiQA37iXlsMa+nChhhLVOZOvP8Wsc+i2 mRozvXqSlcVHVAHZc4disOvecaCsUpODYuQ0nWl0vBogLasxHB2xnAMC98MvIae5g9Bb duunSLKQTHDo5tQ1vEVt1y8p7gzTn/qP+N3kyOklffxSfySHMi2lMe2/zGURylNfnSHY qI41VnJaZkwSTgx4vwU+TNNHD5WPzfiOXAR/kTP+ePg9UpBwMdeVZlGPieNqHD+Kudqc i9ItAGKd7pRZA1rWZFcrDyM5cvi7k3Pzv7MEU3fMHwshFOHlKqy6cmmkKLX3My6ogUL0 RO6g== MIME-Version: 1.0 X-Received: by 10.194.184.140 with SMTP id eu12mr78359327wjc.78.1435236762560; Thu, 25 Jun 2015 05:52:42 -0700 (PDT) Received: by 10.27.179.96 with HTTP; Thu, 25 Jun 2015 05:52:42 -0700 (PDT) Date: Thu, 25 Jun 2015 14:52:42 +0200 Message-ID: To: PHP internals , Dmitry Stogov Content-Type: multipart/alternative; boundary=047d7bacc2c066b05705195719a1 Subject: Allow exceptions in __toString() From: nikita.ppv@gmail.com (Nikita Popov) --047d7bacc2c066b05705195719a1 Content-Type: text/plain; charset=UTF-8 Hi internals! Currently it's not possible to throw an exception from __toString() - instead you will get a (real) fatal error. This is becoming more and more problematic as time goes on, e.g. with PHP 7 an exception can be triggered as a result of a VM error or even a parse error. I'd like to lift this restriction. A patch can be found here: https://github.com/php/php-src/pull/1364 Apart from allowing exceptions, the patch also converts two leftover recoverable fatal errors relating to __toString() into Error exceptions. Furthermore the patch makes sure that we correctly (i.e. without leaks and without superfluous notices or other side-effects) handle __toString() exceptions in the engine. This includes concatenation and interpolation, but also things like writing $foo->$object or ${$object}. zend_parse_parameters() and Fast ZPP also deal with exceptions correctly. However what it doesn't do, and what I wouldn't consider feasible to do, is ensure that every single string conversion in library functions is exception safe. Personally I don't think this is a blocking issue, as the worst that can happen is usually an additional superfluous warning to be thrown, or something similar. If cases like this turn up, we can specifically target them. It should also be noted that whatever issues with exceptions-safety may remain, they already exist now (plus those the patch fixes), because the two aforementioned recoverable fatal errors can be converted to exceptions (and anyone doing blanket ErrorException conversions will do this). So basically the question here is, is this partial solution acceptable for us? Thanks, Nikita --047d7bacc2c066b05705195719a1--