Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91089 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42615 invoked from network); 5 Feb 2016 18:36:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2016 18:36:01 -0000 Authentication-Results: pb1.pair.com header.from=me@daveyshafik.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=me@daveyshafik.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain daveyshafik.com from 209.85.161.182 cause and error) X-PHP-List-Original-Sender: me@daveyshafik.com X-Host-Fingerprint: 209.85.161.182 mail-yw0-f182.google.com Received: from [209.85.161.182] ([209.85.161.182:33693] helo=mail-yw0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F7/B4-07203-F8BE4B65 for ; Fri, 05 Feb 2016 13:36:00 -0500 Received: by mail-yw0-f182.google.com with SMTP id z185so57957779ywf.0 for ; Fri, 05 Feb 2016 10:35:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daveyshafik-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=29qKAkQwfPd3tN+7bvWgpTO9+rhiCEWWIz+haiJQ3ic=; b=DjGIgq3Ae/uy+7yHDSg3fNWlLX6UyrQ+VaDyhLU/GOzbwmJT4uhZVbtlHeOMey+tDq h5XypkCnCD+IEYuYyGMVWoUUyBp1E10Uwuzl238kWj3OKRbRzyf9+24+ilCNO8vuvHQO baIAB01M+uf9tQKBXZZBtj8z+AZYicjgk0sVWI8vea3c3CQtSXk/NzOQ07z3Pc15lPnK OXKU3tQ2IC3YRUBcp2CHL5MHeKTdtVdKwbLhVyzsT24jQ8GLHwsBNtjCzockaQ2XGHzA HkYoXLDTOuQuvJfP1TwCJFNbDqnbLayguRIPJfzwkwwVsdz42Gn1xkvH+tJB4l0ZVkdd 7qBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=29qKAkQwfPd3tN+7bvWgpTO9+rhiCEWWIz+haiJQ3ic=; b=glTxDfWfHZfVAa0ChstPz5oO6LcmzXR2MZZdvblUUQULa3pCMzpqc04AIdDfiI/Cgh h7P+Qb0dNIMkaFQHziWS1cgkZvRHOgM06ItJcoM73jVmQCr2jxsEZ9UYUPgXwoQLV7KG yi+p63GDMe2emmwHf9g/avp+WVnulKUnNZ0H3EjVJUb7ylpNE2a57vngLVI552fitf3a kuaG0EbCl3gnuVPc8E6eLy0A13oBK0TJUTWCXyahCLyAAHSfYOVFo3+H1qiaD6MgKdU+ OqmFMIOu0JOId3MrTuqbJFEoK98U/+EIy2PT9MKJOLbtkUdogMHTcGK2eb4OxfjznHNW 7arA== X-Gm-Message-State: AG10YOR2KlXNMTkHFRGbr7vVzXzK24Q/R8O8IqBRVNjA4bKrj2mcoggLgAiBT+Dl+6gxWyzbe9sZXRqltcRrPK/C MIME-Version: 1.0 X-Received: by 10.129.138.135 with SMTP id a129mr8268347ywg.185.1454697356967; Fri, 05 Feb 2016 10:35:56 -0800 (PST) Sender: me@daveyshafik.com Received: by 10.129.159.193 with HTTP; Fri, 5 Feb 2016 10:35:56 -0800 (PST) In-Reply-To: References: <56B233C0.10301@mprelu.de> Date: Fri, 5 Feb 2016 13:35:56 -0500 X-Google-Sender-Auth: BQ0b-qyvoflPIczoYJfNCi-jgdg Message-ID: To: Pierre Joye Cc: Sara Golemon , Matt Prelude , PHP internals Content-Type: multipart/alternative; boundary=94eb2c07e598380429052b0a1f53 Subject: Re: [PHP-DEV] Re: [RFC] Add PHP_ENGINE Constant From: davey@php.net (Davey Shafik) --94eb2c07e598380429052b0a1f53 Content-Type: text/plain; charset=UTF-8 As an aside, having this kind of #ifdef type stuff also allows us to write forward compatible scripts without worrying about invalid syntax breaking older versions. On Fri, Feb 5, 2016 at 11:20 AM, Pierre Joye wrote: > On Thu, Feb 4, 2016 at 2:00 AM, Davey Shafik wrote: > > On Wednesday, February 3, 2016, Sara Golemon wrote: > > > >> > I think Dan raises some interesting points, although I think > >> zend_version() > >> > is often used for feature detection so they try to put a zend version > in > >> > there to be helpful i.e. HHVM x.y.z === PHP a.b (feature-wise). > >> > > >> That's exactly why PHP_VERSION is faked in HHVM. Because that's how > >> users use it. Essentially, we're treating PHP_VERSION as "PHP > >> language specification version X.Y" So for example, hhvm 3.12.0 > >> conforms to phplang-spec 7.0.0 so it defines HHVM_VERSION to tell what > >> it is, while PHP_VERSION exists for all those scripts that were > >> written under the assumption that there's only one PHP runtime. > >> > >> I would actually suggest that if something like this RFC goes through, > >> we formally define PHP_VERSION in exactly that way. As a language > >> specification conformance advertisement. PHP_ENGINE_VERSION would be > >> the build ID for the actual runtime implementation. In the case of > >> the reference implementation, these numbers would be identical, so > >> there would be no effective change. In the case of other > >> implementations, they'd differ. For example on HHVM you'd have: > >> PHP_VERSION=7.0.0, PHP_ENGINE=hhvm, PHP_ENGINE_VERSION=3.12.0 > >> > >> All that said, I'm not convinced we *need* explicitly enumerated > >> constants like PHP_ENGINE, but for that 0.1% of scripts that care who > >> they're running under, it would certainly unify that detection in a > >> useful way. > >> > >> To the question of "are we just replicating browser detection and all > >> its problems?", I'd offer that perhaps the solution lies not in more > >> constants, but in Reflection. For example: > >> > >> class ReflectionLanguage { > >> public function isSupported($feature): bool; > >> public function variableSyntaxConformance(): string; > >> public function strictTypehints(): bool; > >> } > >> > >> Some of these would be compiler constant-ish, others might be per-file > >> (like strictTypeHints()). > >> > >> ^^ The above is a half-baked idea, please alter/destroy it at will. > >> > > I am also really not convinced we need a PHP_ENGINE_* set of > constants. It defeats the purpose of these constants. > > Each non php.net implementation could (should?) have a > and _ constants, for > instance, HHVM and HHVM_VERSIONS_* constants. These constants can then > be used to do the required work-around for bugs or to use > implementation specific features. > > > Unfortunately Sara, the types of things you generally have to work around > > are minor things, like differences in DOM, or the inability to > json_encode > > DateTimeImmuteable > > > > I do however like the idea of feature detection - I wonder if perhaps we > > could do something where it's done at compile time and therefore > minimally > > impacts runtime? > > This could be what you actually need. A #ifdef equivalent for PHP. I > remember a discussion about adding these features to the core to allow > to enable/disable portions of a script at the parsing/compilation > level. Doing so allows mixing codes being valid for various > implementations inside a same file. It is especially important for > features using syntax not compatible with a php.net's PHP > specification (for instance). > > I am not very keen about that either as I prefer to use separate > files. However it seems to be where we could move forward for these > kind of needs? parser/compilation time constants or expression (like > HAVE_FOO in C for example but only defined by the respective engine > and maybe extensions) as well as at runtime (as normal PHP constants). > Just a thought :) > > Cheers, > -- > Pierre > > @pierrejoye | http://www.libgd.org > --94eb2c07e598380429052b0a1f53--