Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83265 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 760 invoked from network); 20 Feb 2015 05:49:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Feb 2015 05:49:13 -0000 Authentication-Results: pb1.pair.com header.from=zeev@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=zeev@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.223.175 as permitted sender) X-PHP-List-Original-Sender: zeev@zend.com X-Host-Fingerprint: 209.85.223.175 mail-ie0-f175.google.com Received: from [209.85.223.175] ([209.85.223.175:42079] helo=mail-ie0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 04/12-25547-8DAC6E45 for ; Fri, 20 Feb 2015 00:49:12 -0500 Received: by iecrp18 with SMTP id rp18so5510793iec.9 for ; Thu, 19 Feb 2015 21:49:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:references:in-reply-to:mime-version :thread-index:date:message-id:subject:to:cc:content-type; bh=A9lB/MrQtrwTZgkMaXX8oMS/WudZxWQ+xWB0r30g2Lk=; b=GcXHBODPeAw1OiHLoj0KjQvenJQFPQvZ94YDnfaXrzpglhzf3F7iWq9W3988HYBlKX XrSFeDdn/oSeTBttUlEj68lLJubpbjc1mZM15yqFaGOoraVGB0VxHpvCKYG02rqB4U4w Ob4tr5WEJ9SaxQ36oQ/yu25qixxximvrmEh009A3foUv889j4MhHar1HeXM9Nb2pAMdv ahCB0a6rYpsUsg3WCaRDDIa+4kgVxCq6rpRRXXxp3Yt6sKtnLvEq1glIjiv+36PaW5TM FjEtxlx5DMHK7xRluwC3SRZXp0EuFdHlCjZS3RT/WaRV0IXv5oWI1p3gPV6rHGcDhXaX 3Z/g== X-Gm-Message-State: ALoCoQnH5hMLgWnsYnNrqj+smYzxXm5FfTP0cQy0rvQv7NIb7BF6+9c/R3LGBKwv4C2NWks04QgUikpgVXCVa8JnWlUChwkI8rawe5d3XJDYoaKB7rtk6nc1Ou24aY6VQnpvXsvGPYHQFEUQnqK1Jqu1/lsw0ogHqw== X-Received: by 10.51.16.1 with SMTP id fs1mr9614362igd.8.1424411349757; Thu, 19 Feb 2015 21:49:09 -0800 (PST) References: In-Reply-To: MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQLHLVYiZDxG2qv2xcIw64vTIniiyZsLQ5Ig Date: Fri, 20 Feb 2015 07:49:08 +0200 Message-ID: To: bishop@php.net Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: RE: [PHP-DEV] Nightmares on type hints, annotations, and aop... From: zeev@zend.com (Zeev Suraski) Bishop, Pardon me for saying so, but I don't think you're on to a huge scoop here. Scalar type hints - of all the kinds we've been talking about here, be them strict, weak or coercive - can be easily emulated with a couple of lines of code, we all know that. It's been known for years that strict hints are is_*() else error equivalent, that weak hints are (mostly) just casts, etc. Saying the class type hints can be emulated with is_a() calls wouldn't shock anybody either. However, the conclusion you seem to draw from that, few language designers would agree with. Adding first-class, reflectable, analyzable syntax - is worlds apart from the situation today - regardless of what type of scalar hinting we talk about. Once we introduce language-level syntax for this pattern, usage will *explode* compared to what it is today. Explode, not increase. Tools would be updated to support (and take advantage) of this new data - in a way they can't practically do with userland 'emulation' of this behavior. Best practices will be updated. Doc formats will be changed. Etc etc. Last, note that you only focused on userland functions. Things are a bit different with internal functions. The different proposals on the table all propose to change - in one way or another - the way internal functions behave. This is much less intuitive to emulate using userland code, for obvious reasons. So no, I don't think we're making a bigger deal out of it than it is. Scalar type hints are a huge deal, and the fact you can emulate them in userland code today doesn't change that in any way. Thanks, Zeev > -----Original Message----- > From: bishop.bettini@gmail.com [mailto:bishop.bettini@gmail.com] On > Behalf Of Bishop Bettini > Sent: Wednesday, February 18, 2015 2:18 PM > To: PHP internals > Subject: [PHP-DEV] Nightmares on type hints, annotations, and aop... > > After a spate of literal coding nightmares, I woke needing to commit these > thoughts to the list. These may have been raised before, I can't > remember, > these debate has been raging for so long. > > > THING 1: Hints are just is_* wrappers > > function f(scalar $s, int $i) { } > > effectively is sugar for: > > function f($s, $i) { > if (! is_scalar($s)) throw new \InvalidArgumentException(); > if (! is_int($i)) throw new \InvalidArgumentException(); } > > > THING 2: Hints are truthy callables > > function my_mixed($m) { > return (null === $m || is_string($m)); } function f(is_scalar $s, > is_int $i, > my_mixed $m) {}; > > > THING 3: Pre- and post- blocks to define contracts, establish formal join > points, with or without hints from above > > function f($s, $i, $m) > before { > if (! is_scalar($s)) throw new \InvalidArgumentException; }, inside { > $fp = fopen($s, 'r'); > return [ $i, $m ]; > }, > after ($retval) { > assert(is_array($retval) && 2 === count($retval)); }, finally > ($retval) { > fclose($fp); > if ($retval instanceof \Exception) { > // I got here by an unhandled exception > } > } > > weave('before', 'f', function ($s, $i, $m) { > syslog(LOG_DEBUG, __POINTCUT__); // is 'f' > } > > > I had to get these off my chest. Forgive me their implementation > ignorance. > I am yet tired and uncaffeinated. To the void I commit their bodies... > > bishop