Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:19530 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10312 invoked by uid 1010); 9 Oct 2005 11:47:00 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 10297 invoked from network); 9 Oct 2005 11:47:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Oct 2005 11:47:00 -0000 X-Host-Fingerprint: 84.60.24.221 dslb-084-060-024-221.pools.arcor-ip.net Received: from ([84.60.24.221:18178] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 7B/40-54476-33309434 for ; Sun, 09 Oct 2005 07:46:59 -0400 Message-ID: <7B.40.54476.33309434@pb1.pair.com> To: internals@lists.php.net Date: Sun, 09 Oct 2005 13:46:32 +0200 User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: de-DE, de, en-us, en MIME-Version: 1.0 References: <00A2E2156BEE8446A81C8881AE117F192C15D5@companyweb> In-Reply-To: <00A2E2156BEE8446A81C8881AE117F192C15D5@companyweb> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Posted-By: 84.60.24.221 Subject: Re: AW: [PHP-DEV] return /* by reference */ new Foo() in PHP4 From: oliver.graetz@arcor.de (=?ISO-8859-1?Q?Oliver_Gr=E4tz?=) Matthias Pigulla schrieb: >>>So, in case of "return new", wouldn't it make sense to remove the >>>warning as the code is 'legal'? And please, don't start a new "it's >>>just a friendly notice" flame war. >> >> It's just a notice, tune your error_reporting level accordingly. > > > Sorry, but that is just a stupid killer argument. I thought I had > written something like "please, don't start a new *it's just a friendly > notice* flame war". Jep, that would be a valid argument if one could not just adjust error_reporting level but also the "error_throwing" behaviour. Some people want to get notices, they just don't want to get THIS notice. So if [throw_levels] only_variables_can_be_returned_by_reference = create_temp_and_shut_up_like_other_languages could be configured this would be a valid argument ;-) Other languages can pass objects by reference, not only variables. And in the (conceptionally) most advanced languages like Ruby even returning a 3 means returning an object. A function defined as returning by reference should always quietly create anonymous containers if the code returns non-variable-stored values. This most prominently happens with return new Classname(); And I personally also believe that function &huba() { return 3; } should implicitly be interpreted by PHP as $internal_variable_with_random_or_no_name=3 return &$internal_variable_with_random_or_no_name; The name doesn't matter as the caller doesn't want to know it. > May I conclude that what you really want to say is: > > "Yes, return /*byref*/ new Foo() _is_ bad code _unless_ inside Foo's > constructor, $this is passed around and somebody somewhere stores yet This somebody should be PHP. > another reference to it. Accept that you wrote broken code: return new > Foo() is wrong, it needs to be return $tmp =& new Foo()." > > Shaking his head, > Matthias I second that. Let's go to the disco ;-) OLLi ____________ Backup? Backup? ...I knew I forgot something!