Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60486 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36993 invoked from network); 6 May 2012 03:47:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 May 2012 03:47:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:45948] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3C/F2-30075-364F5AF4 for ; Sat, 05 May 2012 23:47:48 -0400 Received: by vbjk13 with SMTP id k13so1539435vbj.29 for ; Sat, 05 May 2012 20:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=0Qd/8CGjFPevm/P2/hJbCk6cZVQs1j3YcbiwIWrXH/o=; b=elaxj+sS8hD8rXF8s/RHs8tvAbhy7tIY+/+yPmK0lviTIstW4L1OjlRUZgm4QTJ4Vz aXZY/3qgQPhcTXkMrQO63k+K5aloWa6NEV4mk4F6cj8VPV2/uXX2sEG94NjEIEocVxnd yXDzOW60+dj0o5ZxzSUvCJwZLmZiqj053K642qeh4HHqK9KfC3V4G7PnmQmbudcXPXl+ dhPS8K5bf9ijlmuZV+Bo6htbTkIlb+y6OcBbA+zj5jRpaqRKaagJJCuDkKTGSW9hJrJ9 TZb7qVnTJNmG+lXQtXN2SQn9pifwA+yVcvNk9wDcH+V04EJL+dtH0HEPS4wOxx8yw3NC jmhg== Received: by 10.52.34.165 with SMTP id a5mr4675667vdj.79.1336276064490; Sat, 05 May 2012 20:47:44 -0700 (PDT) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.220.180.203 with HTTP; Sat, 5 May 2012 20:47:23 -0700 (PDT) In-Reply-To: References: Date: Sun, 6 May 2012 11:47:23 +0800 X-Google-Sender-Auth: L_2K4m97Zk0Lgt1AjAh05GnsKJo Message-ID: To: Devis Lucato Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] catching exception using a variable passed by reference From: laruence@php.net (Laruence) 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. > > =C2=A0function foo(&$exception) >> { >> =C2=A0 =C2=A0 try { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 throw new Exception('foo error'); >> =C2=A0 =C2=A0 } catch (Exception $exception) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 var_dump(gettype($exception)); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 echo $exception->getMessage() . "\n"; >> =C2=A0 =C2=A0 } >> } >> 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, 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! --=20 Laruence =C2=A0Xinchen Hui http://www.laruence.com/