Re: Nightmares on type hints, annotations, and aop...

From: Date: Fri, 20 Feb 2015 06:34:50 +0000
Subject: Re: Nightmares on type hints, annotations, and aop...
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-83267@lists.php.net to get a copy of this message
Hi Bishop, On Wed, Feb 18, 2015 at 9:18 PM, Bishop Bettini <bishop@php.net> 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

« previous php.internals (#83267) next »