Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101550 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18948 invoked from network); 5 Jan 2018 14:33:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jan 2018 14:33:42 -0000 Authentication-Results: pb1.pair.com header.from=andreas@dqxtech.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=andreas@dqxtech.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain dqxtech.net from 209.85.215.46 cause and error) X-PHP-List-Original-Sender: andreas@dqxtech.net X-Host-Fingerprint: 209.85.215.46 mail-lf0-f46.google.com Received: from [209.85.215.46] ([209.85.215.46:37062] helo=mail-lf0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 32/DA-45945-3CC8F4A5 for ; Fri, 05 Jan 2018 09:33:39 -0500 Received: by mail-lf0-f46.google.com with SMTP id f3so5347786lfe.4 for ; Fri, 05 Jan 2018 06:33:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=uIxmm8MvxCaiBR6KlXux41c9q8XmyFPyqUr330CD/ko=; b=pXp0zYUoWce1iCFZR0LH+zZ1FRmQz1NqfYlmHFkAfIw3KjMM/7YLJHkFvqvIcANv/o MxECDTQIHmZF3hAuL7vcC3DxdI+ThSCIL9J+QnJNOqwLuGCXJAs9DIIX2Gjhc+55muMs p6FoEdBEfj1SDRu+rvAgTin/rcK4hapyQACTV4XsDBlth/GqzGBeuCaFOiGFFvyXR0Zn rUuDnZeSz8iGDXvhhlTIyieaB+N+GWLDNMMCfYzVFJ5/3dFtnNcYAejBjpPPeExmDgm6 7paC96tt+/zoqfrfG18Nxu/OhjRnZSz4sLU+oza1yJlRBSZ6N/6Ek95O3sfOuhPKX7T4 /XQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=uIxmm8MvxCaiBR6KlXux41c9q8XmyFPyqUr330CD/ko=; b=f+CtDTyihikZjS5/6L5k0ITuHw1k+dBLY56x97sfwiMDSeXRbhp2/TB0T8oJxGeoU/ XWJhozyEUF8YrMeqoSKyhOTyARWHgCro1/KMgW7/kGIwjzHM9OV1P51xlK5NMNngkHcG tYdWy1L5pNQky3sSrZaj62TxH3IWRdwbST8eiM/RTyNPzRFlaorhIsXzyP70YXp6+8fc vJe31qWsTot+IRxOLf9nFrWJeAacJaWLxJcT63wTAfUIUgd4z4Cmap3RzC2/SoPhhP9G G4+dS4kCW4LhBc199q0CAyvbbJeu0UkCzyUzqV8oi33NBHe48ZsrwBi+peT42c/LSo2i DR3g== X-Gm-Message-State: AKGB3mLKmJLFgUHyn6LgbKq/ElyX3aiub1MWwb+FPBBbWZ86dpPsrwpf Gz4O7wVy9ulzSfFRc17ihhlR5AQZ X-Google-Smtp-Source: ACJfBotNDueiwmMAEAD0h5HjzAnQ3hk1ztA3o1vMeCiVZTZGoIC7nSoTjKs3TjErDlxR8NMhbUt5Bg== X-Received: by 10.46.25.213 with SMTP id 82mr1746808ljz.56.1515162815096; Fri, 05 Jan 2018 06:33:35 -0800 (PST) Received: from mail-lf0-f51.google.com (mail-lf0-f51.google.com. [209.85.215.51]) by smtp.googlemail.com with ESMTPSA id 39sm1053921ljb.49.2018.01.05.06.33.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jan 2018 06:33:34 -0800 (PST) Received: by mail-lf0-f51.google.com with SMTP id h5so5352686lfj.2 for ; Fri, 05 Jan 2018 06:33:33 -0800 (PST) X-Received: by 10.25.204.71 with SMTP id c68mr1728934lfg.39.1515162813424; Fri, 05 Jan 2018 06:33:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.25.201.210 with HTTP; Fri, 5 Jan 2018 06:33:12 -0800 (PST) In-Reply-To: References: <9a3a8760-f65a-a5c0-b318-1830a9a986c3@gmail.com> <9352F6DF-9940-49A2-9B1D-FA9258E9738E@lerdorf.com> Date: Fri, 5 Jan 2018 15:33:12 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Dan Ackroyd Cc: Michael Morris , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Strong Typing Syntax From: andreas@dqxtech.net (Andreas Hennings) On 5 January 2018 at 11:35, Dan Ackroyd wrote: > On 5 January 2018 at 02:01, Michael Morris wrote: >> >> what if the underlying zval wasn=E2=80=99t a zval but a separate >> class specific to the data type but implementing the same interface as >> zval? > > I believe the only sensible answer to that is 'mu', as that question > is based on misunderstanding. > > The internals of the PHP engine is C, and zvals are structs not > classes, and so there is no interface. In userland classes are also > zvals. http://www.phpinternalsbook.com/php7/internal_types/zvals/basic_s= tructure.html I think a good beginners intro is this, http://php.net/manual/de/internals2.variables.intro.php Yes, these things are structs, and there are no interfaces. It would be possible, in theory, to create a different struct for type-locked variables, where the type is not stored with each instance, but in the opcode. Or perhaps separate structs per type. This would obviously be a huge amount of work, and a radical change to the language, so I do not imagine this going to happen any time soon. Every place in code that currently deals with the _zval_struct would then have to consider all other structs. The opcode could then be optimized for such type-locked variables, and this would reduce cost in memory and performance. The next best thing would be to keep the existing _zval_struct also for type-locked variables, and still try to optimize the opcode as if the type is known at compile time. Still a lot of work, I imagine, because it still affects every place where we deal with a variable. The third option is to keep the implementation as if all types are dynamic, and only add some type checks here and there, which can be globally enabled or disabled. This is what other gradually typed languages do, as pointed out by Rowan Collins, > The biggest issue with any proposal, though, is going to be performance. = I don't think this is an incidental detail to be dealt with later, it is a = fundamental issue with the way type hints in PHP have evolved. PHP is extre= mely unusual, if not unique, in exclusively enforcing type constraints at r= untime. Other languages with "gradual typing" such as Python, Hack, and Dar= t, use the annotations only in separate static analysers and/or when a runt= ime debug flag is set (similar to enabling assertions). > > Also, I think people who try to guess at how to make changes to the > engine, are doing a small disservice to people who have already tried > to implement this. This is a dilemma. I think there are some people with valuable opinions on language design, which did not find the time yet to study the engine implementation. So, either we risk occasional ignorant ideas, or we will miss some valuable contributions. I personally want to eventually study the engine in more detail, but I don't think I need to completely self-censor myself until then. Instead, I have to make a judgement call each time if my limited understanding is sufficient to allow a meaningful contribution to the discussion.