Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89913 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8004 invoked from network); 28 Dec 2015 20:29:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Dec 2015 20:29:26 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.169 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.160.169 mail-yk0-f169.google.com Received: from [209.85.160.169] ([209.85.160.169:36069] helo=mail-yk0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 15/66-51216-5AB91865 for ; Mon, 28 Dec 2015 15:29:26 -0500 Received: by mail-yk0-f169.google.com with SMTP id v14so19880359ykd.3 for ; Mon, 28 Dec 2015 12:29:25 -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:from:date:message-id :subject:to:cc:content-type; bh=GRIPT7o3wmmHSh8bvA2akCflgXQ8sd8wDceD+0A+wSc=; b=t0CuIVivR6lSj/j7qNKQQ8Vz1/cRCkYLJCXFiLhfcn5KZTdKf7IZKDDYZiDr6C25IB eM84aYyowKE73qMQ3K49aQXsJ05eQi4zCjVLWL9j+SfVKdEA1jLQQvv2J3k7vdO64CPO 4K8Vw2lCc24MvBqod2lUuhJRQF4P8qC0nqrLi0shRk7QIyv8SxcU/LnrCQTlmL/2cP3U q5uMh9ov6yrmdP0JA6pT1qrElSpZ8Jth8f9TM2Rq3G19YCE17kuKrLG9O5bIeDNIeWpe 14dPKjybXT5Rgk7RQhUQNN0AKM4PvgymRjo2UcxfKfjMZS9gkaPUSCS/IRbLTkf8ZTd4 GPYg== X-Received: by 10.13.216.71 with SMTP id a68mr19107008ywe.0.1451334563320; Mon, 28 Dec 2015 12:29:23 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.129.88.139 with HTTP; Mon, 28 Dec 2015 12:28:43 -0800 (PST) In-Reply-To: References: <56811E49.1040106@php.net> Date: Tue, 29 Dec 2015 05:28:43 +0900 X-Google-Sender-Auth: T4sB6d0U9Zh5z0xLZSYuG0npx20 Message-ID: To: Elijah Johnson Cc: =?UTF-8?Q?Fran=C3=A7ois_Laupretre?= , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Make strict mode more strict? From: yohgaki@ohgaki.net (Yasuo Ohgaki) Hi Elijah, On Tue, Dec 29, 2015 at 12:47 AM, Elijah Johnson wrote: > 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 = ...; then potentially the same. > > On assignment would look something like this (pseudo-code): > > bool checkType(zVal, newZVal) > { > bool throw_error = false; > if (MODE_STACK_TYPE_OBJECT) > { > if (isObjectType(zVal)) > { > int class_id= GET_PLACEHOLDER_CLASS(zVal);// ie. > zVal.value or value of current object > if (class_id !== GET_CLASS(newZVal)) > { > throw_error = true; > } > } else if (IS_OBJECT(newZVal) && !IS_NULL(zVal){ > throw_error = true; // assigning an object to a non-null, > 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. Now I understand why you think zval modification is needed and concern about performance. My proposal checks basic types simply. i.e. Only checks if a variable is object type or not. Simple and quick. Object(class) is type, so it makes sense checking class consistency. If we check object's class, not only the class but also ancestor classes should be checked. This may affect performance. I'm not sure if this worth the effort. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net