Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89910 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89852 invoked from network); 28 Dec 2015 15:47:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Dec 2015 15:47:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=tomac120@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tomac120@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.169 as permitted sender) X-PHP-List-Original-Sender: tomac120@gmail.com X-Host-Fingerprint: 209.85.214.169 mail-ob0-f169.google.com Received: from [209.85.214.169] ([209.85.214.169:32838] helo=mail-ob0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 45/24-51216-99951865 for ; Mon, 28 Dec 2015 10:47:38 -0500 Received: by mail-ob0-f169.google.com with SMTP id bx1so117184397obb.0 for ; Mon, 28 Dec 2015 07:47:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=MrSHxhQPty9V9A9hruO1fTJouEi61Tvhcahy5JuidqA=; b=EyY69mD/+6zwpaB4ryF7BB+Idzdfgev7AqGVuiuGnImyQ7iTHfHTZ9fEpcR6OUlwah +3d+dp8Cj0/M0sv3pWLBIml3SOGYZO6m8UUlLZJETdJCYEUQjJ2fgyzw8Ait+n+6FOQ8 7Faux8cXSpBhKI2oUy6goqz1zxyiJdJqMjZUe8r3q7NIJBY39xg1liUcp5PNFZRzt51s 5XKseNITYOHWKiRyYPJyYpo3BYpEUuZS+aDRN9Vkg2T5FGBFZU5q7LxuErS32IjBokhm 60iqi59qws75I8ZCwSsxJrGeHfSTZK9OC7lZS8eTQWi0VFm5NcToSsHqBKaaZpUCjRHt GkDg== MIME-Version: 1.0 X-Received: by 10.182.73.225 with SMTP id o1mr34512386obv.80.1451317655017; Mon, 28 Dec 2015 07:47:35 -0800 (PST) Sender: tomac120@gmail.com Received: by 10.202.220.212 with HTTP; Mon, 28 Dec 2015 07:47:34 -0800 (PST) In-Reply-To: References: <56811E49.1040106@php.net> Date: Mon, 28 Dec 2015 10:47:34 -0500 X-Google-Sender-Auth: 8InzBIVdT50TBla_AGn9XHMQAgI Message-ID: To: =?UTF-8?Q?Fran=C3=A7ois_Laupretre?= Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=089e0160b7c6489e190527f73937 Subject: Re: [PHP-DEV] Make strict mode more strict? From: ejrx7753@gmail.com (Elijah Johnson) --089e0160b7c6489e190527f73937 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Some additional observations - On Mon, Dec 28, 2015 at 10:03 AM, Elijah Johnson wrote= : > Thanks, > > On Mon, Dec 28, 2015 at 6:34 AM, Fran=C3=A7ois Laupretre > wrote: > >> Hi, >> >> Le 26/12/2015 21:35, Elijah Johnson a =C3=A9crit : >> >>> Can you explain your statement that this would be a huge and complex >>> work? You must mean that there would be multiple places in the php sour= ce >>> code where variables are assigned? I'm not yet discussing performance, = but >>> only the aspect of adding the feature. >>> >> >> There may other options I don't know but, AFAIK, this implies adding an >> optional type hint at the zval level. This type hint should be verified = at >> least before each conversion. Copy-on-write is an other issue, as it is >> currently not compatible with zval type hints. Seeing only variables wit= h >> well-defined names, and focusing on arrays, only scratches the surface. >> Everything happens at the zval level. So, IMO, attaching type hints to >> variables and properties is a huge and complex work. >> >> Regards >> >> Fran=C3=A7ois >> > > I think I see what you are saying. Copy on write takes a reference to the > entire z-val in two local variables, so a type-hint at the z-val level > would be shared. > > This returns us to the insight of the original mailer who suggested that > an object or array variable should be typed by its first-assigned object. > This would simply need to be a global mode - stack-mode-legacy, > stack-mode-static-object-types, and stack-mode-super-strict for those who > want basic types also. > > I'm not saying that this is ideal, just that we need to compromise a bit > to accommodate our existing code base and performance issues. > > The proposal for an additional z-val which stores the class name in the > zval.value member and is counted as null could accommodate the case where > the user wants to assign the type before he has an object. > > I think this is the best option. Another theory I had was to store the > types at the context level in some kind of array, but its really too much= . > > The idea just now proposed of 3 global modes will eliminate the issue of > storing at the z-val level. The mode "stack-mode-static-object-types" is > even already compatible with every line of code that I have properly > written in PHP. > The mode "stack-mode-static-object-types" would ideally also prevent assignment of an object with a current string value, or string placeholder value. What I mean by placeholder value - an additional z-val type "t" returning true for IS_NULL, where the class name id is stored in value union. This would be declared by type hint ex. MyObject $object; If the variable is assigned, MyObject $object =3D ...; then potentially the same. On assignment would look something like this (pseudo-code): bool checkType(zVal, newZVal) { bool throw_error =3D false; if (MODE_STACK_TYPE_OBJECT) { if (isObjectType(zVal)) { int class_id=3D GET_PLACEHOLDER_CLASS(zVal);// ie. zVal.value or value of current object if (class_id !=3D=3D GET_CLASS(newZVal)) { throw_error =3D true; } } else if (IS_OBJECT(newZVal) && !IS_NULL(zVal){ throw_error =3D true; // assigning an object to a non-nul= l, non-object } } if (throw_error) { // assign to null, generate TypeError // ie. Warning: assign of type to type, assigned null value return false; // prevent assignment by caller } return true } Some additional checks would likely be necessary to prevent placeholders from being assigned and returned, and if strict mode was implemented, there would need to be a second placeholder type (or some other means of identification such as a constant). Implementing placeholders isn't a necessary step, but it would make for very readable code. --089e0160b7c6489e190527f73937--