Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60491 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77533 invoked from network); 6 May 2012 11:11:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 May 2012 11:11:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=devis@oracolo.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=devis@oracolo.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain oracolo.com designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: devis@oracolo.com X-Host-Fingerprint: 209.85.214.42 mail-bk0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:37737] helo=mail-bk0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8C/39-30075-66C56AF4 for ; Sun, 06 May 2012 07:11:34 -0400 Received: by bkcik5 with SMTP id ik5so3320037bkc.29 for ; Sun, 06 May 2012 04:11:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :x-gm-message-state; bh=bdcwD6jpN0FJbZVhSCnRzY86Rap9odFulttj1oaZIRo=; b=H+w7mhmUgTN2qQGVLOd9ZMUVG/j/M2L7Bjy11F4SUDX96XxRx2ZvTmQavRAXxNWdpm A+4Egp+fP3pHFk9cQMCeX+en7l2uPXplujtNtGVie3trd1LmbevgdLi2F2zAVycTObOL ubEkQI4SPgxCN+ziZQ9XN3Mgu62r02Luu3ohYJopDp8EATmw03EqCXQpDtHJyhDYYs6V m+dKdJQU43kXZRvVGoIB/dW8+/ZMQ+dYPxcUpaXcJKElILgFXoHODdKZx2rKdttkCJW0 P/uRi30kHjw6Fv+adR3uGDmIi+nuobG48LeWTcXzM+pXfugKvrRxuyTCu8x3TZyffhnn aOEg== Received: by 10.204.151.211 with SMTP id d19mr4218052bkw.63.1336302690992; Sun, 06 May 2012 04:11:30 -0700 (PDT) MIME-Version: 1.0 Sender: devis@oracolo.com Received: by 10.204.139.138 with HTTP; Sun, 6 May 2012 04:10:50 -0700 (PDT) In-Reply-To: References: Date: Sun, 6 May 2012 12:10:50 +0100 X-Google-Sender-Auth: zVSPA3Inbkjq0z0t5mUGDnK0_ew Message-ID: To: Laruence Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=0015175ce0a63582f004bf5c37fa X-Gm-Message-State: ALoCoQmNoINVNG6ETz9uhbQMxmssQe2JtDPq4c1YuZTtxVs1Nc88/wUGJK6HYHhD8TPBQKcUJ/15 Subject: Re: [PHP-DEV] catching exception using a variable passed by reference From: devis@lucato.it (Devis Lucato) --0015175ce0a63582f004bf5c37fa Content-Type: text/plain; charset=UTF-8 Hi Laruence, the solution you suggest would work though it makes it all a bit more verbose... I noticed also that the original variable is completely removed from the function scope, which is probably a bug. I'll raise a ticket, thank you ;-) Devis On 6 May 2012 05:04, Laruence wrote: > On Sun, May 6, 2012 at 11:47 AM, Laruence wrote: > > On Sun, May 6, 2012 at 8:40 AM, Devis Lucato wrote: > >> Hi, > >> > >> I stumbled upon this code while working with a variable passed by > >> reference, I was wondering if someone could provide some feedback before > >> raising a ticket, just in case PHP (5.3.6) is doing what it's supposed > to > >> do. > >> In the code below I would expect "catch" to change the variable as > >> an assignment would do, but that doesn't happen. > >> > >> function foo(&$exception) > >>> { > >>> try { > >>> throw new Exception('foo error'); > >>> } catch (Exception $exception) { > >>> var_dump(gettype($exception)); > >>> echo $exception->getMessage() . "\n"; > >>> } > >>> } > >>> foo($error); > >>> var_dump(gettype($error)); > >> > >> > >> > >> Expected: > >> > >>> string(6) "object" > >>> foo error > >>> string(6) "object" > >> > >> > >> Current result: > >> > >>> string(6) "object" > >>> foo error > >>> string(4) "NULL" > >> > >> > >> > >> It looks like "catch" is creating a completely new variable in the > scope, > >> also removing the existing one from it. > Hi: > after a deep look, I think it's not a bug. > > the exception in the catch block is only a local var of that block. > > I think you should change you codes like following to accomplish > your requirement: > > function foo(&$exception) > { > try { > throw new Exception('foo error'); > } catch (Exception $e) { > var_dump(gettype($e)); > $exception = $e; > echo $e->getMessage() . "\n"; > } > } > foo($error); > var_dump(gettype($error)); > > thanks > > Hi, > > > > could you file a bug at bugs.php.net? :) > > > > thanks > >> I appreciate this is an edge case, if not a bug is it worth adding it to > >> http://php.net/manual/en/language.exceptions.php or somewhere under > >> http://www.php.net/manual/en/language.references.php ? > >> > >> > >> Thank you! > > > > > > > > -- > > Laruence Xinchen Hui > > http://www.laruence.com/ > > > > -- > Laruence Xinchen Hui > http://www.laruence.com/ > --0015175ce0a63582f004bf5c37fa--