Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85871 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95502 invoked from network); 19 Apr 2015 20:23:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2015 20:23:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=kelerest123@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=kelerest123@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.46 as permitted sender) X-PHP-List-Original-Sender: kelerest123@gmail.com X-Host-Fingerprint: 209.85.218.46 mail-oi0-f46.google.com Received: from [209.85.218.46] ([209.85.218.46:36736] helo=mail-oi0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 35/13-57547-5CE04355 for ; Sun, 19 Apr 2015 16:23:33 -0400 Received: by oift201 with SMTP id t201so111545309oif.3 for ; Sun, 19 Apr 2015 13:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=2cpa+p84GqELMgvcB+W7MIAXAEvM/FUp6RN4Z+OeSnU=; b=aXvcsUOGJ60+uKW7CSjhfJ7i97nhOPmwIfBwqU+q6yMyICSyELNl47kZ4zZ2fIAvsG bWmDEu0UvH6DttTNUzbFtJm3fM09ouR3cLyFFtIaj73LWkdNHuU3hKlL6OpDIzIpSGL4 v1wzb1AQcMjH6oeKwlcHziYVcIhMyatKUSDeUQIDP+w4eHmINyeqcupxA9rT1be+O+1X gQwy1L35JAS/trq5vqV+inhXm1O00xDUfwqRIS/VA6SgBrRXxQJQGRm5UhL+uT9sQfpV 0deJFdtqePpCvdbSFHRaX2G+tdetOzKZv1ccuKFwgvijEsfFVeIXl1CdE98J34JThrLq wDjA== X-Received: by 10.182.106.197 with SMTP id gw5mr11518106obb.30.1429475010450; Sun, 19 Apr 2015 13:23:30 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.213.135 with HTTP; Sun, 19 Apr 2015 13:23:10 -0700 (PDT) In-Reply-To: References: Date: Sun, 19 Apr 2015 22:23:10 +0200 Message-ID: To: Marco Pivetta Cc: Ferenc Kovacs , Julien Pauli , Andrew Faulds , PHP Internals Content-Type: multipart/alternative; boundary=089e015366e0369a2605141996a6 Subject: Re: [PHP-DEV] Closure::call() to access private data, really ? From: kelerest123@gmail.com (=?UTF-8?B?SmFrdWIgS3Viw63EjWVr?=) --089e015366e0369a2605141996a6 Content-Type: text/plain; charset=UTF-8 My opinion is, that we simply have to change PHP closures' scoping to be more similar with JavaScript functions' scope. That would solve the current challenge pointed on by @jpauli, thus closure would have access to private object's members only if it was defined in that object's class / method definition, so then engine can know that it was programmers intention. I mean something like this: privateMember = new stdClass; }; class C { private $privateMember; private $closure; function __construct() { $this->closure = function() { $this->privateMember = 32; }; } function callClosure() { $this->closure->call($this); } } $c = new C; $c->callClosure(); // would succeed $p->call($c); // Fatal error ?> What do you think about this kind of behavior? Best regards, Kubo2 2015-04-17 22:03 GMT+02:00 Marco Pivetta : > On 17 April 2015 at 18:43, Ferenc Kovacs wrote: > > > For the record this isn't exclusive to Closure::call, afaik the same > thing > > is possible with Closure::bind() since 5.4 > > http://3v4l.org/hlFS4 > > And there are/were a decent amount of discussion (and AFAIR even hydrate > > libraries using this trick) about this, for example: > > > > > http://ocramius.github.io/blog/accessing-private-php-class-members-without-reflection/ > > > > Also note that this is the only way to access private properties by-ref > (yes, I do need that for my horrible use-cases. No, don't ask about it.) > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ > --089e015366e0369a2605141996a6--