Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94116 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8375 invoked from network); 19 Jun 2016 09:34:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jun 2016 09:34:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.213.42 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.213.42 mail-vk0-f42.google.com Received: from [209.85.213.42] ([209.85.213.42:35084] helo=mail-vk0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9B/09-18862-53766675 for ; Sun, 19 Jun 2016 05:34:46 -0400 Received: by mail-vk0-f42.google.com with SMTP id j2so164333743vkg.2 for ; Sun, 19 Jun 2016 02:34:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=5LPEkHS9ZoJ6Yakl0qJJtByydwzgVMjyx0s64qXhU7A=; b=0adIlH8ksbfG01d8ruSTv+llr4mtxXZD8EZd0uZ7nKQI5DOq4IXGHJAW67r0UYBh7+ ZDXS2s52tF9D5n6vOyFJnfsO/y0i8xn9lt+l9hIjPJMVtvsVR4GPZu57MfZeE0J15ywl OFil5cieL1KbDY0BzASB+KafFU/cAXHxlmHMrMgKcKQ21ydL+u0ywwVE4V3M++UpL12W /xQnhaQ/bLXig07f6hZ1plvc7+fdUfYD4zUYjoLUFf9ES8+Ps2yYIcx+61ziu3kcSypu mX0EXqAh9IMDbfga9sV+QlG6rg1GLKGMBTl1PvNuf7S2pfhyydwu+iOhNXXSU3rYLqRU EcVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=5LPEkHS9ZoJ6Yakl0qJJtByydwzgVMjyx0s64qXhU7A=; b=ZReUGjYsJ1oKxiXY1CUigetvbluZm4pCOLqo+XP4Dik/R/vC3JJtwcB3WWfgngtdTp Uq+UlxdwBP/ZbscumdchHKlHejuSuxnLwk8XmAnORlp0vjw8zpMkvEXTiGDxCeUByhlJ AF0ZqlK5Qy7Odsjq3Za9Tboa2l8t7u+K5GUXw3J/YSOqYMyfgvm6vWNJjnNo84L6KlzL ZzBOJaHSuSuYdwxWcpKQTx/NL6UA2ZhvSIv5vv7Vn6YsFGyL7n/20UoDp+iBi03SddGK xhBxvdeCmZU3pDujZkv/O6XwnjFViXdP02hHZvqzSuU1izO8ad+HkMZST7Z9khq907P8 9QXw== X-Gm-Message-State: ALyK8tKyb4AvOIQPnKVLxLm2vZ30oKhyeUDcdQGElm7MMXtSj4QW27oO6QDZGGCxEdIE2+LWTEPhMzBDiRuQGQ== X-Received: by 10.159.34.104 with SMTP id 95mr4270302uad.86.1466328883214; Sun, 19 Jun 2016 02:34:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.88.148 with HTTP; Sun, 19 Jun 2016 02:34:42 -0700 (PDT) In-Reply-To: References: <20160617202344.2868F1A80C02@dd1730.kasserver.com> Date: Sun, 19 Jun 2016 11:34:42 +0200 Message-ID: To: Niklas Keller Cc: Ryan Pallas , Stanislav Malyshev , Thomas Bley , "internals@lists.php.net" , michael.vostrikov@gmail.com Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] New escaped output operator From: rasmus@mindplay.dk (Rasmus Schultz) > Did you know that you can alias namespaces, too? Yes > You can always add more functions to a namespace even spread accross multiple files Same problem: no autoloading. You would have to add require_one statements - which, as said, is not really possible with Composer packages... On Sun, Jun 19, 2016 at 9:53 AM, Niklas Keller wrote: > > Rasmus Schultz schrieb am Sa., 18. Juni 2016, 17:44: >> >> > Add a couple parens and its completely implementable in userland >> >> If we could autoload functions, I bet that's what everyone would be doing. >> >> At the moment, no one is able to commit to that pattern, because it >> doesn't scale - you can't just keep adding to a list of global >> functions (and files) that get aggressively loaded whenever you render >> a view, even if each view uses only one or two of them... >> >> So in practice, you minimally end up with something like this: >> >> >> >> >> >> ... >> >> But that isn't really practical either, since you can only cram so >> many functions into the same class - at which point you start adding >> more classes... >> >> >> >> >> >> >> It quickly gets ugly, messy and confusing. > > > Did you know that you can alias namespaces, too? > > > > > You can always add more functions to a namespace even spread accross > multiple files. > >> Then I start thinking about crazy solutions like tokenizing the >> template file first and dynamically adding require_once statements for >> any functions discovered being used, which would be more convenient, >> but quite overly complex for such a small problem - and we're still >> talking about occupying the global namespace with lots of functions. >> >> And so you likely end up accepting that it's ugly and inconvenient, >> and you resign yourself to use-statements and static methods, or >> fully-static classes, which I've taken to referring to as >> "psuedo-namespaces", since we're really abusing classes as a kind of >> namespace for functions, just so we can get them to autoload. >> >> Functions just aren't all that convenient or useful in PHP, because >> they largely depend on manual use of require_once, which feels really >> ugly and old-fashioned (since everything else autoloads like it's >> supposed to) - and it isn't even always possible, since, for example, >> you can't (reliably) know where a Composer package is located relative >> to your project or package; it depends on whether your project is >> currently the root package (e.g. under test) or an installed package >> in the vendor-folder. >> >> I really like pure functions - they're neat, simple and predictable. >> In Javascript (and other languages) I always use functions first and >> resort to classes only when there's a real clear benefit. In PHP, I >> feel like I'm almost always forced into using classes for everything, >> mainly because that's what works best in PHP and creates the least >> rub. >> >> This has been bothering me for many years - and I wish that I could >> propose a solution, but I really don't have any ideas. >> >> Can we do something to improve and encourage the use of functions in PHP? >> >> >> On Sat, Jun 18, 2016 at 12:27 AM, Ryan Pallas >> wrote: >> > On Fri, Jun 17, 2016 at 2:23 PM, Thomas Bley >> > wrote: >> > >> >> you can simply add the context to the current output operator: >> >> >> >> >> >> (=strip_tags) >> >> >> >> >> >> >> > >> > Look at that. Add a couple parens and its completely implementable in >> > userland now with no language changes required. >> > >> > >> >> Regards >> >> Thomas >> >> >> >> Stanislav Malyshev wrote on 17.06.2016 22:14: >> >> >> >> > Hi! >> >> > >> >> >> Most of output code is an output of properties of database entities, >> >> >> and >> >> >> only in some cases it's needed to concatenate HTML into string and >> >> >> then >> >> >> print it with unescaped output. Escaped output operator can be >> >> >> useful. >> >> Also >> >> >> we output data not into the void and not into simple text file, but >> >> >> into >> >> >> HTML-document which has a certain format (markup). Also this is >> >> >> logical >> >> - >> >> >> to have both forms, escaped and unescaped. >> >> > >> >> > This has been discussed on the list a number of times. Main issue >> >> > with >> >> > this kind of proposals is that escaping is context-dependent. E.g. >> >> > htmlspecialchars() would not help you in many scenarios - e.g. it >> >> > won't >> >> > protect you from XSS if you ever place user-controlled data in HTML >> >> > attributes. Having operator for each of the possible contexts does >> >> > not >> >> > really looks feasible, and having it for only one of them and not the >> >> > others would be misleading people into thinking this operator is >> >> > generic >> >> > and can be used in all contexts safely. >> >> > >> >> > -- >> >> > Stas Malyshev >> >> > smalyshev@gmail.com >> >> > >> >> > -- >> >> > PHP Internals - PHP Runtime Development Mailing List >> >> > To unsubscribe, visit: http://www.php.net/unsub.php >> >> > >> >> >> >> >> >> -- >> >> PHP Internals - PHP Runtime Development Mailing List >> >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> >> >> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >