Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83267 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9776 invoked from network); 20 Feb 2015 06:35:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Feb 2015 06:35:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.42 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.192.42 mail-qg0-f42.google.com Received: from [209.85.192.42] ([209.85.192.42:50249] helo=mail-qg0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F1/E3-25547-5B5D6E45 for ; Fri, 20 Feb 2015 01:35:33 -0500 Received: by mail-qg0-f42.google.com with SMTP id z107so12277166qgd.1 for ; Thu, 19 Feb 2015 22:35:31 -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=ONrDRpa6ddrq+h4EKMqo61xKAFt/yaGipUEpo3FQPI8=; b=mukchfJ918+a9HItjvCpiNbYXKlAXN/F6i16ZyzCwC92kYySb42tDCjLOYHWfi1DbA UeASKlTE1Dvt1CCHr4A9NJfZDNvFAmiRI+700gbqWJ8/0aeLez6gOVHctc4ozBtOCaFa UYnPLQybBHmla0bc7xAbBpkzNwyUUXY4v3u0hSutve+1IEa0Wek5SOI4bG32Qf8Kwi07 uXTumnLBCvVLJqLQ9Afz1k4uKLZih3utpw7CWTEHymHo7S8GFE2SvI4ThY9BwffFIdWe YXDmYR7ImArQefX8FnygvlKoBIICxXdaTBvMiRHKy6shM1dUg4X1nsdl8O9DIHmXvoLW 803A== X-Received: by 10.229.192.5 with SMTP id do5mr21752408qcb.12.1424414130968; Thu, 19 Feb 2015 22:35:30 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.229.198.8 with HTTP; Thu, 19 Feb 2015 22:34:50 -0800 (PST) In-Reply-To: References: Date: Fri, 20 Feb 2015 15:34:50 +0900 X-Google-Sender-Auth: TiBwz8MEj9H_fOwDn2TeYyBZsmc Message-ID: To: Bishop Bettini Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11337bfc4a20a5050f7f4257 Subject: Re: [PHP-DEV] Nightmares on type hints, annotations, and aop... From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11337bfc4a20a5050f7f4257 Content-Type: text/plain; charset=UTF-8 Hi Bishop, On Wed, Feb 18, 2015 at 9:18 PM, Bishop Bettini wrote: > 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) {}; > > This is interesting idea. I'm sure it will be much slower than type hints as it calls functions, but it's still interesting idea. i.e. Cost of calling functions are not cheap. Inline optimization will help, but it increases byte code size. Type hint implementation is a lot simpler than this. 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' > } > Although it has similarities, AOP and DbC cannot share blocks/etc. AOP is for production codes, DbC is _not_ for production codes, but only for development and testing. These are 2 distinct features. Regards, > -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11337bfc4a20a5050f7f4257--