Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88920 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 33495 invoked from network); 22 Oct 2015 15:48:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Oct 2015 15:48:47 -0000 Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.176 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:33002] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/C1-18485-E5509265 for ; Thu, 22 Oct 2015 11:48:46 -0400 Received: by wijp11 with SMTP id p11so38640932wij.0 for ; Thu, 22 Oct 2015 08:48:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=717vyOh45nN2BYqkZxgKlNjxbado2IIUzNyxajNT+5w=; b=ZIK9b3EB64x+opZ27dZ9WLa/M5GGoSmVg2HkYVMWnalVbn8Yia+5Yy7byiDOlPITP5 BrC06sqAE46bqdo5neGDNn80aKkbl5wgQ76UI8UHoMwZFrqUYlxF3hhkIQKRcRVK5mr/ zdcEUOSIEE9ysgLR/GmX2SAmqSfBgV7/Ft1M7tEC/QSQBAVA6fIP6wtPk4VoiPZhl2zQ 6BgtUsImIXuTINfbNHm6oMX6TV6vy8YklVX/fc/26HcSpP0V662mU7FC2KwxAXeVgLF+ 8CVKumKHl9HvHsw1iqUJ9dL8n6eeyHxUlXQiav3wI0FGXuph5z8Uq7CWs/8Vd4DvqOGz vswQ== X-Received: by 10.194.19.169 with SMTP id g9mr17704867wje.64.1445528923324; Thu, 22 Oct 2015 08:48:43 -0700 (PDT) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.194.7.105 with HTTP; Thu, 22 Oct 2015 08:48:03 -0700 (PDT) In-Reply-To: References: <01f001d1052b$bed5cbb0$3c816310$@belski.net> <022301d1053b$06a91a50$13fb4ef0$@belski.net> <02c801d10588$9009fd80$b01df880$@belski.net> Date: Thu, 22 Oct 2015 17:48:03 +0200 X-Google-Sender-Auth: pb-LVUHi5eShg7QNWzfJavDHljA Message-ID: To: Alexander Lisachenko Cc: Nikita Popov , Anatol Belski , Xinchen Hui , Dmitry Stogov , PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Re: Forbid rebinding scope of closures created by ReflectionFunctionAbstract::getClosure() From: jpauli@php.net (Julien Pauli) On Mon, Oct 19, 2015 at 12:34 PM, Alexander Lisachenko wrote: > 2015-10-19 12:19 GMT+03:00 Nikita Popov : > >> This change is primarily targeting userland methods, so your use-case is >> exactly the one this is supposed to prevent. Note that you can still use >> ->bindTo($object). The only thing you cannot do is ->bindTo($object, >> get_class($object)). > > > > It's very pity ( It was a very interesting feature that gives a birth for > userland AOP, without it part of framework functionality *will be lost*. > From the list of attached bugs I can see that all weird stuff happens only > with internal classes/functions/methods. I never have seen a segfaults in > my code that heavily uses closure rebinding with userland methods/classes > and expect it to work in all future versions of PHP, starting from >=5.4. > > I don't know PHP engine well, but this feature with scope rebinding for > methods allows some interesting patterns, like "Spy", "Field initializer", > "Lazy proxy initializer", etc. We just take one method and bind it to > another scope to perform an additional logic if needed. > > Maybe, apply your patch only to internal functions (restrict them to have > $this inside) and simple functions? This will cover most bugs, but won't > break an exisitng code. This is very tricky use case IMO. We should absolutely focus on stability, and if we can't find a way to make things safe, we forbid them for the stability sake. If there are no way to have stable things, well, that's pitty but it's like that. We can't allow PHP to release with a known crashing behavior. Perhaps we'll find new ways to do things in 7.1 or next 8.0. Julien.Pauli