Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:5479 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46829 invoked by uid 1010); 15 Nov 2003 00:26:33 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 46773 invoked from network); 15 Nov 2003 00:26:33 -0000 Received: from unknown (HELO mail1.panix.com) (166.84.1.72) by pb1.pair.com with SMTP; 15 Nov 2003 00:26:33 -0000 Received: from panix5.panix.com (panix5.panix.com [166.84.1.5]) by mail1.panix.com (Postfix) with ESMTP id E9DC048869 for ; Fri, 14 Nov 2003 19:26:32 -0500 (EST) Received: (from analysis@localhost) by panix5.panix.com (8.11.6p2-a/8.8.8/PanixN1.1) id hAF0QWQ05991 for internals@lists.php.net; Fri, 14 Nov 2003 19:26:32 -0500 (EST) Date: Fri, 14 Nov 2003 19:26:32 -0500 To: PHP Internals List Message-ID: <20031115002632.GA2311@panix.com> References: <20031112174553.GA23321@panix.com> <20031112174553.GA23321@panix.com> <5.1.0.14.2.20031114222245.038dc6d0@127.0.0.1> <20031114225112.GA27104@panix.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20031114225112.GA27104@panix.com> User-Agent: Mutt/1.4.1i Subject: Re: [PHP-DEV] return by reference behaviors in PHP 5 From: danielc@analysisandsolutions.com (Daniel Convissor) Hello Again: Pardon the followup to myself... On Fri, Nov 14, 2003 at 05:51:12PM -0500, Daniel Convissor wrote: > Though, it seems the behavior should be consistent -- sometimes I'm too > logical :) -- so returning a variable is okay and the rest of it should be > blocked, OR rework the system so anything can be returend. I did some more testing on this front and ran into some VERY weird behavior which seems to reinforce the point I made above. The test script is below by sig. Thanks, --Dan -- FREE scripts that make web and database programming easier http://www.analysisandsolutions.com/software/ T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7th Ave #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 Data['DATETIME'] = 'st 10-21-03 06:01 et'; /* * Commenting out next three lines changes output to: * Ref 1 * Fatal error: Cannot return overloaded elements or * string offsets by reference... line 43. */ if ( preg_match('/st (\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d) et/i', $this->Data['DATETIME'], $Atom) ) { } } function &Ref() { return $this->int; } function &RefAdd() { return ++$this->int; // Line 43 } function Not() { return $this->int; } } $y = new x; /* * Uncommenting the next two lines changes the output to: * Fatal error: Only variables or references can be returned * by reference... line 43 */ // $a =& $y->RefAdd(); // echo "
RefAdd $a"; $b =& $y->Ref(); echo "
Ref $b"; /* * Uncommenting the next two lines changes the output to: * Ref 1 * Not 1 * RefAdd 2 */ // $c = $y->Not(); // echo "
Not $c"; $d =& $y->RefAdd(); echo "
RefAdd $d"; ?>