Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:24934 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10306 invoked by uid 1010); 24 Jul 2006 16:12:40 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 10291 invoked from network); 24 Jul 2006 16:12:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jul 2006 16:12:40 -0000 Authentication-Results: pb1.pair.com header.from=boards@gmail.com; domainkeys=good DomainKey-Status: good X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: boards@gmail.com X-Host-Fingerprint: 64.233.184.230 wr-out-0506.google.com Linux 2.4/2.6 Received: from ([64.233.184.230:11557] helo=wr-out-0506.google.com) by pb1.pair.com (ecelerity 2.1.1.3 r(11751M)) with ESMTP id F8/4E-04178-671F4C44 for ; Mon, 24 Jul 2006 12:12:39 -0400 Received: by wr-out-0506.google.com with SMTP id 68so713945wri for ; Mon, 24 Jul 2006 09:12:36 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:reply-to:organization:to:subject:date:user-agent:references:in-reply-to:mime-version:content-type:content-transfer-encoding:message-id; b=Vm6xM76Ws9iSXKrQZaeeSk03rOmCvCyAMeVX0YtgQSJZyU/gGesgRgpxa8GpYAkjBkK2hb5xe7bim+hT6Nq72Nniny51PGr3mUE/118YgrhFnSOiSM+XOF9qLpqnZlJxFfUQYLWKfoSBzBf7wooiYXPEY/HCNxdJtL2shWCXUYQ= Received: by 10.54.150.5 with SMTP id x5mr3948442wrd; Mon, 24 Jul 2006 09:12:34 -0700 (PDT) Received: from vaio ( [67.184.91.45]) by mx.gmail.com with ESMTP id g9sm4826938wra.2006.07.24.09.12.34; Mon, 24 Jul 2006 09:12:34 -0700 (PDT) Reply-To: boards@gmail.com Organization: LX To: internals@lists.php.net Date: Mon, 24 Jul 2006 11:12:30 -0500 User-Agent: KMail/1.9.3 References: <44C4ECC6.8080401@kaluma.com> In-Reply-To: <44C4ECC6.8080401@kaluma.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart4240331.Td6xIOZtAi"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-ID: <200607241112.31285.boards@gmail.com> Subject: Re: [PHP-DEV] Pass by reference (5.1.1 vs 5.1.2) From: boards@gmail.com (Matt Sicker) --nextPart4240331.Td6xIOZtAi Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Monday 24 July 2006 10:52, Rishad Omar wrote: > Hello, > > I've upgraded from 5.1.1 to 5.1.2 and discovered the following > unexpected difference. Best shown by example. > > function getArray(&$arr) > { > $arr[] =3D 12; > } > > getArray($p =3D array()); > print_r($p); > ?> > > In php 5.1.1, the $p is passed correctly as reference and so returns > with the value 12 in its first element. I regard this as correct > behaviour. In php 5.1.2, the $p is passed by value. So on return, $p > is still empty! This can be fixed as follows: > $p =3D array(); > getArray($p); > > > > The following example works, as expected, in both 5.1.1 and 5.1.2. > > class A > { > public $i =3D 9; > } > > > function doAmend(A &$a) // & not required because class instance > passed by reference by default > { > $a->i +=3D 30; > } > > doAmend($b =3D new A); > print_r($b); // this prints the value of member i as 39 > as expected. > > ?> I'm guessing it has something to do with a memory leak. Either that, or=20 scope; creating a variable inside of a function call probably goes out=20 of scope after the function returns. Enable error_reporting(E_ALL| E_STRICT) and see what happens. =2D-=20 Matt Sicker --nextPart4240331.Td6xIOZtAi Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQBExPFv5tcAKF5t41MRAtQFAJ9ykiAqWc6HIdHDuFEK8mJadcXoiQCcD8on hNggGAyLh5+FqTFQ6YTefFU= =Yvff -----END PGP SIGNATURE----- --nextPart4240331.Td6xIOZtAi--