Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83011 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71412 invoked from network); 17 Feb 2015 22:03:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Feb 2015 22:03:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.215.54 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.215.54 mail-la0-f54.google.com Received: from [209.85.215.54] ([209.85.215.54:41869] helo=mail-la0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B4/64-34644-8CAB3E45 for ; Tue, 17 Feb 2015 17:03:53 -0500 Received: by labpv20 with SMTP id pv20so38344994lab.8 for ; Tue, 17 Feb 2015 14:03:49 -0800 (PST) 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:date:message-id:subject:from :to:content-type; bh=AWyXIT6ZCE2QEkBNbZcw1ftPFWE3ltfF2AAuDxjABhM=; b=EzJ8LXkR2yPYsZF2pQAeBOh4PtCjMH48liZ1di4jifzIIQpxviVDqNmZWyGg2eSywn 5z3b9UPjzEmIWkzrW1l+XMNjPsZShfeSVW1OAGpuDdlpTE/95msh2lD7gHxjwNBRX5KQ +ossQz//cKIkRYrp8EinoVDeATtQzfsIrVh0lxGI+4kgeVVANJmv8vyMKqdwd/A1lp5X g9XSnDj0qPaaTUPH/1FQdr28lKq/bwplifh62Sej6gA/xOtYNN3jAUEXruEY7/rHeZKG HyTD4q47XPCi7OpqlD//Xm+Lw/7S45NctP17BpwvnhWx689TjzkVi+HuCx58+QxZb4FQ MUkA== X-Gm-Message-State: ALoCoQkJnD0ShoAbpJpO4rnZKzNqNOpTQSdALFHIa6u2L5aZzcWgr2BvumrEIBV8MFechAmjmy+K MIME-Version: 1.0 X-Received: by 10.112.36.69 with SMTP id o5mr654573lbj.59.1424210629417; Tue, 17 Feb 2015 14:03:49 -0800 (PST) Sender: php@golemon.com Received: by 10.112.38.73 with HTTP; Tue, 17 Feb 2015 14:03:49 -0800 (PST) X-Originating-IP: [2620:10d:c082:1003:22c9:d0ff:fe87:295b] Date: Tue, 17 Feb 2015 14:03:49 -0800 X-Google-Sender-Auth: xzHCHEGdS6qlStlH4pT78jfUU5o Message-ID: To: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Scalar Type Hints v0.4 From: pollita@php.net (Sara Golemon) Based on conversations here and elsewhere on the internet, I'd like to put forward a rough gameplan for scalar types which I hope addresses most concerns. This is back-of-the-napkin and I'm not asking for a committed yes/no, just pre-rfc set of thoughts. Please don't get hung up on specific names, we can debate those in the coming week(s), I'm only looking for large architectural issues. 1) Introduce scalar types for primitives: bool, int, float, string, resource, object (we already have array) 1a) Introduce meta-types as pre-defined unions (we can add custom unions in a later rfc). A possible list may be as follows (again, we can argue what's in this list separately): * mixed: any type * scalar: (null|bool|int|float|string) * numeric (int|float|numeric-string) * stringish (string or object with __toString()) * boolish (like mixed, but coerces to bool) * etc... 2) Define a way to enable "strict mode" (we'll be weak by default). 2a) Userspace impact: Strict mode will throw a recoverable error on type mismatch. Weak mode will coerce the type according to conversion rules (See #3), throwing a recoverable error if coercion isn't possible. 2b) Internal impact: The same rules apply to internal functions as userspace functions HOWEVER, we use the types present in ZEND_ARG_INFO structures, not zpp. This has the net effect that every internal function remains effectively untyped unless specifically opted in by means of updating their arg info struct. In weak mode, internal functions coerce according to conversion rules. 3) Tighten up coersion rules for weak mode. i.e. "10 dogs" for an int is a violation, but "10" is acceptable. 3a) Userspace impact: We're in a clean slate state, so this is "safe" from a BC perspective. 3b) Internal impact: Again, behavior remains unchanged unless the ZEND_ARG_INFO struct has been modified to add proper typehints. If typehints have been added, then the more aggressive coersion rules apply during typehint validation. I really want to underline the design expressed in #2b and #3b. zend_parse_parameters()'s types have been removed from the equation in this proposal. This means that, until someone audits a given function and makes the decision to give it a type, it will effectively behave as though always weak, regardless of the caller's flags. This enables us to give the same contractual behavior internally and externally, while still implicitly treating internal functions as a bit special for the purpose of moving forward. -Sara