Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89172 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45444 invoked from network); 11 Nov 2015 10:01:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Nov 2015 10:01:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.50 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 74.125.82.50 mail-wm0-f50.google.com Received: from [74.125.82.50] ([74.125.82.50:32876] helo=mail-wm0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 85/DF-21426-EE113465 for ; Wed, 11 Nov 2015 05:01:19 -0500 Received: by wmec201 with SMTP id c201so173757691wme.0 for ; Wed, 11 Nov 2015 02:01:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=UYKuP0rDrfvasiINZDvzUu+pRZ63hzT66sAHOiuRF7k=; b=AiSxNhN2Dni2KYPGubey4O5UMx2lXfFWhxr+bzgLEQzXubWpBOLvlPJOcZ0Wl3gSzp Yzh/l6D0BoKJ0iZ8H438DY4YeWhmd2FcrNL6GdYMwXjpGcqbrBeBbMUxArHZxE7VROAN dGTZaMR7T3OlIWjfH262a+KP6YfsBI7BOQCjc8msjdWztNYQ/wPYXeOlSzf85rRUufud GoDKeJnx/oGgnQPyCgrmUfG4L/VF51VQjZzmy22AtQXjsFWgnYo1nAbGgqA2zgRM2X1H KDoqncS2Pt6Gr3rNPrkZpfkKtJiuiVDI8fdPhCvSlUSmPYLbQPxoGr8go5b9Qk/ktiPI 5gKQ== MIME-Version: 1.0 X-Received: by 10.194.60.179 with SMTP id i19mr9112099wjr.135.1447236075732; Wed, 11 Nov 2015 02:01:15 -0800 (PST) Received: by 10.27.84.70 with HTTP; Wed, 11 Nov 2015 02:01:15 -0800 (PST) In-Reply-To: References: <563B6ED1.1030601@gmail.com> Date: Wed, 11 Nov 2015 11:01:15 +0100 Message-ID: To: Steven Hilder Cc: PHP Internals , Leigh , Derick Rethans , Niklas Keller , Rowan Collins , Joe Watkins , Dmitry Stogov Content-Type: multipart/alternative; boundary=047d7ba973ce334680052440e873 Subject: Re: [PHP-DEV] Null bytes in anonymous class names From: nikita.ppv@gmail.com (Nikita Popov) --047d7ba973ce334680052440e873 Content-Type: text/plain; charset=UTF-8 On Tue, Nov 10, 2015 at 11:04 PM, Steven Hilder < steven.hilder@sevenpercent.solutions> wrote: On Mon, 09 Nov 2015 16:48:57, Leigh wrote: > >> On 9 November 2015 at 15:27, Steven Hilder >> Can you share your patch? >> > > See > https://github.com/php/php-src/compare/master...stevenhilder:hide-anon-class-suffix > > Feedback very welcome :) > > It should be possible to return the sanitised name without removing it >> internally.(would have to cover the get_parent_class and getParentClass >> versions too, and have a quick audit of other places class names can be >> spat out.) >> > > Yes, that's what I had in mind. The class names are sanitised only for > display in userland; I haven't changed the way that the names are generated > or stored internally. > > I've applied the change to `get_parent_class()` and `get_called_class()`. > Nothing needed to be done for `ReflectionClass::getParentClass()` because > it > returns another `ReflectionClass` object, not the parent's name. > > The `__CLASS__` magic constant and `::class` syntax also needed changes. > The > patch includes a test which shows all of the scenarios that I've accounted > for. Please do let me know if you can think of any others. > > I've also implemented the change to `class_alias()` as I described in my > previous email. > I'd like to clarify some things here from the perspective of the people who implemented this naming scheme. The naming was chosen to be this way intentionally, to combine two behaviors we would like to have: a) Things like get_class() MUST return a class name that uniquely identifies the anonymous class. You should be able to instantiate a new instance of the same class based on it, etc. Having these return truncated names is an absolute no-go, because it would require people to explicitly handle anonymous classes in many context that currently "just work". b) We do not want to display the fully mangled name of an anonymous class in error messages or debug dumps. While the information contained there can be useful, it also significantly bloats outputs. Furthermore we will likely change the exact naming structure in the future, in which case the anonymous class name will no longer contain any directly useful information (maybe some hash). Using a NUL byte conveniently achieves both of these goals. We did not however take into account that this would cause issues with 3rd party tooling that does not support binary data. As such, we may have to change the naming. However we must retain goal a) and would like to retain b). To do this we could use names along the lines of class@anonymous$1, where the uniquely-identifying information is short enough to be no bother when displayed. Generating these kinds of names is non-trivial if you consider caching and may require some changes to the way we perform class bindings. (As a side bonus, depending on how this is done, we might fix https://bugs.php.net/bug.php?id=64291 as well.) Not sure if this is still in scope for PHP 7.0. Nikita --047d7ba973ce334680052440e873--