Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91086 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30208 invoked from network); 5 Feb 2016 16:20:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2016 16:20:48 -0000 Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.52 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.218.52 mail-oi0-f52.google.com Received: from [209.85.218.52] ([209.85.218.52:36384] helo=mail-oi0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/B2-07203-FDBC4B65 for ; Fri, 05 Feb 2016 11:20:47 -0500 Received: by mail-oi0-f52.google.com with SMTP id x21so43901029oix.3 for ; Fri, 05 Feb 2016 08:20:47 -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=KqvrHBEbd0I7GVJtdOabBY438fgZwjNLa3HFFBSBt20=; b=mE6Ekw9o4ecFC2hdk3FUFJ8z7E+wYkLTaO+U+28JLRpHfOj+Bi7869WdjCULzwlQjg 2DBDeH27COCynmREBlbcjpSCNAGEkpzj1/SEeeUaG5J4vdYbsWAVJljh/9VEXkS9pMHV 37L3e1wT16s6tHhzTmywi0WPVIRkF8n57qUVRyqsAIeEoF9Q3DtBy4wI3QMy7GRtCVLf ISP+R8/CvWdydt6iVS0krFzFaDpvEj7sacadT+P1qYq6x1eruXcrYTdZGCiir6aZknd7 sFdsXdSPHiiR9VshxgG3ET6Vu/Li57NQRvnf2QYVuwZIKCiNPJ9OmQ8TlWGOFe8HC8nu OLVw== 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:date :message-id:subject:from:to:cc:content-type; bh=KqvrHBEbd0I7GVJtdOabBY438fgZwjNLa3HFFBSBt20=; b=Cj6DyHFN6befdFR1ItUNF4eRif22Cbe+q0nlYrzMJLMEz/7hKFUDDlGw2Phb7fZVeE kpfMh13U1NJlIcbl+tHgtAieSVLN8+kWl1Yl55AHN/HMOrPwU2tDSJSHq4k8TzNsNWEE vKaORs0/aZOwVvOaqR5lSpAN37lNOMbZqhNjtV+7YbafGrexXZThY1w7ULX3a/0dTd7W GYr6Vw6qTD05/Y4m2wDfcRlIn/GGYcLfqJaL3Mh7Luv5c6Yb//RrqyrytEcUqL9osdpw Yc2jpVaGi2nVE7wIKjSI4Vb+B+nqHouKyNdMQ+022dCc4WjpwY7PkeUzQsNuzuMX7ykw SsiQ== X-Gm-Message-State: AG10YORVic5LJeVdFIhLbZIW4E1C9bgyWM/9vq1YJ0kvPQql20qKcL1tEDWeXlGcHA6Rbq78VeNh9brfM4Ximw== MIME-Version: 1.0 X-Received: by 10.202.102.153 with SMTP id m25mr8811229oik.132.1454689244271; Fri, 05 Feb 2016 08:20:44 -0800 (PST) Received: by 10.202.95.68 with HTTP; Fri, 5 Feb 2016 08:20:44 -0800 (PST) In-Reply-To: References: <56B233C0.10301@mprelu.de> Date: Fri, 5 Feb 2016 23:20:44 +0700 Message-ID: To: Davey Shafik Cc: Sara Golemon , Matt Prelude , PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Re: [RFC] Add PHP_ENGINE Constant From: pierre.php@gmail.com (Pierre Joye) 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