Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83053 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96311 invoked from network); 18 Feb 2015 12:18:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 12:18:21 -0000 Authentication-Results: pb1.pair.com header.from=bishop.bettini@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bishop.bettini@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.173 as permitted sender) X-PHP-List-Original-Sender: bishop.bettini@gmail.com X-Host-Fingerprint: 209.85.217.173 mail-lb0-f173.google.com Received: from [209.85.217.173] ([209.85.217.173:40762] helo=mail-lb0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 71/4D-18888-B0384E45 for ; Wed, 18 Feb 2015 07:18:20 -0500 Received: by lbdu10 with SMTP id u10so683512lbd.7 for ; Wed, 18 Feb 2015 04:18:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:date:message-id:subject:from:to :content-type; bh=VTFhWA6XumpHreH1NkIcfwwcmmJkFuDU1nd5alOru3A=; b=Gy3NBFjCt6JhTgnIILn/2SCFKRG+Qjdt1xFscKk8cmDCk0ztneOiHVyiMH1Oh2IAGy 7lCU3inzV9i/VHL9SCxtMM9rdxl0WHXMTmx2It3jkwmQ5TOMN/oZ4EjpX8DI3EH2ZLDj yxVBfTkib1PhbGZ/ky5a9qHFNINgEQhwM1mrBiABk2zkUT4pl9vYeoPtv3eWf0zkRkgA xWouPZdTU1tZnWplliR5sciQhT2nQubnF11VQJsnx1mKjZTPZm2cd022h8wsqr7+q7m8 yKpHHYho5r1tgSNIK98cUPG09DrlbAnyg9XuXWafW4KLe3zcMfSAQunB9fEM3+CE+GyS 3rJQ== MIME-Version: 1.0 X-Received: by 10.152.184.39 with SMTP id er7mr31790624lac.116.1424261896242; Wed, 18 Feb 2015 04:18:16 -0800 (PST) Reply-To: bishop@php.net Sender: bishop.bettini@gmail.com Received: by 10.152.105.49 with HTTP; Wed, 18 Feb 2015 04:18:16 -0800 (PST) Date: Wed, 18 Feb 2015 07:18:16 -0500 X-Google-Sender-Auth: xjSNvxXzKjN0D12pKSwZJufzZHo Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=001a113467d2648e47050f5bd088 Subject: Nightmares on type hints, annotations, and aop... From: bishop@php.net (Bishop Bettini) --001a113467d2648e47050f5bd088 Content-Type: text/plain; charset=UTF-8 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 --001a113467d2648e47050f5bd088--