Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65656 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77585 invoked from network); 5 Feb 2013 00:56:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2013 00:56:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=cspray.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cspray.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.48 as permitted sender) X-PHP-List-Original-Sender: cspray.php@gmail.com X-Host-Fingerprint: 209.85.212.48 mail-vb0-f48.google.com Received: from [209.85.212.48] ([209.85.212.48:41231] helo=mail-vb0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 45/42-63819-AD850115 for ; Mon, 04 Feb 2013 19:56:58 -0500 Received: by mail-vb0-f48.google.com with SMTP id fc21so4250246vbb.21 for ; Mon, 04 Feb 2013 16:56:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=YM0Byk/z6zp7mJPDi4hmu6YJ9yg2lDlp7ZFmCwf6i6E=; b=w8GtzDZBO+rlkKnSw/Apx014O2ijONg8fLAIezVt2RMc/3ycxXpBxwQl0cfrjPSag7 wi/5Xa+y6kIGi3YalULYUSojC4Q9y7idqsgawSOdu8kw05HUgmCGOLnd/7UtITtvZ5a3 xilP6WG4lVinLP0Bh5VNAiUS/gWGVNJB6pmc6P3TyFRBF/k1TzYVTUuWFvxRaVdeEtiU a/3tv2CCt2mobgnXyO1YBDA59GkysgIpjfH7yYJsQRkdtzdXCC7nVxeJBUmgNjPBqP7K xaP3ywtQlX39cEwmHw36NqrY5oodx1tXAOpF+3rMtyb2EiLcHMddhe3u9mrVOijU2Xto d4Bw== MIME-Version: 1.0 X-Received: by 10.52.17.135 with SMTP id o7mr21778095vdd.70.1360025814407; Mon, 04 Feb 2013 16:56:54 -0800 (PST) Received: by 10.58.229.162 with HTTP; Mon, 4 Feb 2013 16:56:54 -0800 (PST) Date: Mon, 4 Feb 2013 19:56:54 -0500 Message-ID: To: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=bcaec502d7188d9ae704d4efaf4d Subject: SplFileObject::__toString potentially returns false From: cspray.php@gmail.com (Charles Sprayberry) --bcaec502d7188d9ae704d4efaf4d Content-Type: text/plain; charset=ISO-8859-1 There was a previous discussion on the return value of SplFileObject::__toString being an alias to SplFileObject::current() but that was about the design decision why and not really suggesting any kind of change or a technical error. In the discussion it was established that: (1) Changing this would be a BC break (2) It isn't really a bug in the codebase, the docs were just wrong The current implementation has a bug in that current() can potentially return false, if false is returned from the __toString() magic method a catchable fatal error occurs. Code ran on 5.4.11 *nix, Apache 2.2 --TEST-- Ensuring we get appropriate output for SplFileObject::__toString --FILE-- --EXPECTF-- A --------- Diff 002+ Catchable fatal error: Method SplFileObject::__toString() must return a string value in /path/to/splfileobject_tostring.php on line 12 --------- I would say that SplFileObject:__toString() being an alias to SplFileObject::current() makes the use cases for the method very limited and that the current implementation is mistaken in returning current(). I can think of no use case where SplFileObject::__toString() should return this value. If need to get the current line you're probably iterating and in that case should be using foreach() and don't really need to manually take care of that. Even if there is a use case for manually invoking `SplFileObject::current()` you probably aren't casting a string in that situation and a more expressive method call is better. (1) Leave the implementation the way it is and simply return a blank string when current() would return false (2) Change the implementation to return SplFileInfo::__toString() (3) Change the implementation to return entire file contents (4) Return some other unthought of string but remains consistent and logical I am personally partial to (2) or (3) perhaps in 5.5 but (1) could probably happen sooner? Thoughts? --bcaec502d7188d9ae704d4efaf4d--