Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67285 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77318 invoked from network); 3 May 2013 06:08:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 May 2013 06:08:49 -0000 Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.83.46 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 74.125.83.46 mail-ee0-f46.google.com Received: from [74.125.83.46] ([74.125.83.46:63999] helo=mail-ee0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 13/A0-05684-07453815 for ; Fri, 03 May 2013 02:08:49 -0400 Received: by mail-ee0-f46.google.com with SMTP id b57so588655eek.5 for ; Thu, 02 May 2013 23:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=IAh/OwX5SUATSfIIOCexz5jJ6rDFDT8rFmXi+mstkYU=; b=0L5/yvjZJr1D41xVfzkBegjrgWv18nlGj9EjNOXVEEY139kMgBK8jg7f/nTcFE8LXQ dSpM1vtj6FhVeQe0n8DTx+YV5+rxnCcDaGDT6onECzrwGa2NNjmBAk/U9y3gAmVbDQ4O G5WtTjxv42P/0iT4g777FlhrPthOW4heSTqtXPYKKvKbk3ZitsGO93OnADrAAOEif+WA F5pc3z0DVbRZIlHSGpuysinGjppdPvKqd3VRBmRaVTYbW9ccR97IZKjDgP9ktWaS9cS0 nlUuk4yoCo1pFGGIJXfiDIjfvWWoyQMiB3hmD8/qNFYG8jKQXQMjushl0Grm3m+ksWRi esOw== MIME-Version: 1.0 X-Received: by 10.15.23.133 with SMTP id h5mr5219165eeu.12.1367561322315; Thu, 02 May 2013 23:08:42 -0700 (PDT) Received: by 10.14.125.14 with HTTP; Thu, 2 May 2013 23:08:42 -0700 (PDT) In-Reply-To: References: Date: Fri, 3 May 2013 02:08:42 -0400 Message-ID: To: Adam Jon Richardson Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=089e016812bed36db904dbca2e37 Subject: Re: [PHP-DEV] A better error handling approach. From: theanomaly.is@gmail.com (Sherif Ramadan) --089e016812bed36db904dbca2e37 Content-Type: text/plain; charset=ISO-8859-1 On Fri, May 3, 2013 at 1:25 AM, Adam Jon Richardson wrote: > > > Currently, sure. Limiting this functionality to the return statement > seems doable. > It's already possible to do so now without any modifications to the core: function myFunc() { $result = array(null, null); if ($failureCase) { $result[1] = $errorState; } else { $result[0] = $value; { return $result; } list($result, $error) = myFunc(); Again, all you're asking for beyond that is syntax sugar. > > > What you're talking about has many flaws just the same as the > > existing error handling approach. > > > > 1) It depends on order of return values > > Sure, but I've found the convention in Go to be one that hasn't caused > me any trouble (really, the only time I return multiple values is when > I'm returning an error for impure functions.) > And what works in Go may not necessarily work well in PHP. > > > 2) It requires breaking BC in a way that will effect every single PHP > user > > out there. > > How so? > Because you would be changing the return value of every single function in PHP. Anytime you change what a function returns you break BC. > > > 3) It requires re-factoring virtually every PHP function, of which PHP > has > > thousands upon thousands. > > How so? Even just making this possible would allow libraries to wrap > calls to functions like file() and provide a multiple return > equivalent that includes the error information. The core functions > wouldn't have to change. > > If the functions are wrapped to return an array we have to update the documentation for thousands of functions as well as break user space for millions of users. Now array_map('file',$files) has a convoluted error state problem. This isn't as simple of a change as you're making it out to be. > > 4) It doesn't make error handling that much easier in PHP, because you > still > > have to check the error state regardless of how it's obtained. Believe > it or > > not passing back an array is the same thing. All you're describing here > is > > syntax sugar that allows the engine to do list comprehension for you on > the > > fly. > > I might have agreed with you half a year ago, but after coding in a Go > a while, I disagree. This approach has merit. > I'm sure every approach has merit. The problem here is the return on investment for implementing such a change in PHP. It's a lot of work for very little benefit. > > Adam > --089e016812bed36db904dbca2e37--