Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:48670 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26797 invoked from network); 7 Jun 2010 15:21:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Jun 2010 15:21:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=felipensp@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=felipensp@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: felipensp@gmail.com X-Host-Fingerprint: 209.85.161.42 mail-fx0-f42.google.com Received: from [209.85.161.42] ([209.85.161.42:38166] helo=mail-fx0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/51-17184-DC90D0C4 for ; Mon, 07 Jun 2010 11:01:34 -0400 Received: by fxm10 with SMTP id 10so291629fxm.29 for ; Mon, 07 Jun 2010 08:01:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=XlLrKc99weos40OM9Cmht10I4YkJI3YWsbtAAl7zagc=; b=KQUmAayXODx6wszwCZmsUB3reDLTamIKM11xYL0KsViujmbuu2BoflPdKj/VRrMSNB hq5nK7OibNE6I7YALjqaQKR1woNL28NP0GeBFdR2AGjfFF/tfokV0z5n2lWGABnycH96 q7iEu6xJfX741LksX+4xSKDq7QozCkdiWSbgQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=hZBHDAhQnDX/bz2aV8iJnw2Q2GwGuqzUnyCO+A5g7qBk7T4sY8WPAmWDePt0GoS2TW 2esMD+M4p9JDQISPNn9weuxtydHoBb3fZF9wPcWw+xdbCMnJFD6uJa1Z/yR18AJnDaWn uWyGffSESd6CTxRxEPjH+5cvMLbqgq6z/HcNY= MIME-Version: 1.0 Received: by 10.102.165.40 with SMTP id n40mr5018275mue.71.1275922890837; Mon, 07 Jun 2010 08:01:30 -0700 (PDT) Received: by 10.103.160.17 with HTTP; Mon, 7 Jun 2010 08:01:30 -0700 (PDT) In-Reply-To: References: <4C089491.1050305@sugarcrm.com> Date: Mon, 7 Jun 2010 12:01:30 -0300 Message-ID: To: Stas Malyshev Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=0016364c7a69ab4f5c048871f290 Subject: Re: [PHP-DEV] Suggestion: echo function(var)[0]; From: felipensp@gmail.com (Felipe Pena) --0016364c7a69ab4f5c048871f290 Content-Type: text/plain; charset=UTF-8 Hi all, 2010/6/5 Felipe Pena > Hi! > > 2010/6/4 Stas Malyshev > > Hi! >> >> >> function call chaining (f()() if f() returns function), and array >>> dereferencing (f()[0]) - (Stas) >>> >> >> I did patch for f()() - it's referenced at >> http://wiki.php.net/rfc/fcallfcall - but not for f()[] - didn't have time >> for that yet. >> >> It should not be too hard to do, one just has to be careful with refcounts >> so that the returned result could be freed properly and without hurting the >> referred element. >> > > I wrote a patch, but I cannot test all cases, so I'm not sure if is okay at > all. > > What about this approach: http://felipe.ath.cx/diff/array_dereference.diff? > > I've updated the patch, now it works with method call as well. Example: bar()[2]->bar()[0]); // 3 var_dump($foo->bar()[2]->bar()[1]); // array(0 => 1, 1 => 5) var_dump($foo->bar()[2]->bar()[1][1]); // 5 var_dump($foo->bar()[2]->bar()[2]->x); // 10 function test($arr) { $x = $arr; return $x; } $array = array(1, new foo); var_dump(test($array)[0]); // 1 var_dump(test($array)[1]->bar()[0]); // 3 var_dump(test($array)[1]->bar()[2]); // object(foo) http://felipe.ath.cx/diff/array_dereference.diff Thanks. -- Regards, Felipe Pena --0016364c7a69ab4f5c048871f290--