Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81919 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76166 invoked from network); 5 Feb 2015 12:43:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2015 12:43:03 -0000 Authentication-Results: pb1.pair.com header.from=lisachenko.it@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=lisachenko.it@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.169 as permitted sender) X-PHP-List-Original-Sender: lisachenko.it@gmail.com X-Host-Fingerprint: 209.85.212.169 mail-wi0-f169.google.com Received: from [209.85.212.169] ([209.85.212.169:42549] helo=mail-wi0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/E9-27691-65563D45 for ; Thu, 05 Feb 2015 07:43:02 -0500 Received: by mail-wi0-f169.google.com with SMTP id h11so2186095wiw.0 for ; Thu, 05 Feb 2015 04:42:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=3HV9vrsUlULuIvcdcNbzFNb+XHpvhaYSdmiBzGlzxRE=; b=bKOvQVxZRo0dG2UZHkKulvnVzk3rCqfTJSfOlLUNMHkKM00/CyiY9YRAk5TVLUvjul 1ZAfT+jwzi531aeibNhivuDSDCsOHqOOzYzDV1UZlgknv6YsYQhwx7VqIYCGzT4xpsHu +BfBZO3GKj+JUNwqbdu02BZtzLr174Of/tEMVO9uuYYnR2LGGdChKnhvXimoxpmoeVfT GN5G1RljSDDJ3CBgS1GIMHOy6qf1gRLOP0HXGTwNzcbnMMNsWQ7DwRmrVyvztjs1SNL3 3HW7QSbaf72JyksGZ599JcOx2Xm5bPV7WTE3eSl/SA3gXGs0G1KffMH05mQZcZF2ST8c tWyA== MIME-Version: 1.0 X-Received: by 10.180.19.228 with SMTP id i4mr14990360wie.13.1423140179226; Thu, 05 Feb 2015 04:42:59 -0800 (PST) Received: by 10.194.154.229 with HTTP; Thu, 5 Feb 2015 04:42:59 -0800 (PST) In-Reply-To: References: <7740874.yAST26hVNS@rofl> Date: Thu, 5 Feb 2015 15:42:59 +0300 Message-ID: To: Dmitry Stogov Cc: Patrick Schaaf , PHP internals list , Yasuo Ohgaki Content-Type: multipart/alternative; boundary=bcaec53d5507d9343b050e56a478 Subject: Re: [PHP-DEV] Design by Contract From: lisachenko.it@gmail.com (Alexander Lisachenko) --bcaec53d5507d9343b050e56a478 Content-Type: text/plain; charset=UTF-8 2015-02-05 15:32 GMT+03:00 Dmitry Stogov : > Hi Alexander, > > Defining contracts through doc-comments is also possible, but this way is > not native. > On the other hand, if you already have this implemented, we may just reuse > it. > Thanks, Dmitry! This would be a really nice feature on engine-level. Ideally, for PHP7-8, I would like to see a hook system from compile-level to userland, to define a language extension. This feature is highly required for custom DSLs and much more. DbC technique can be also implemented as parse-time weaver. E.g. we define a parser-extension: register_parser_extension(ContractExtension::class); this class will receive an AST of PHP file and check interesting nodes. This node can be annotation or something else: [Contract::Invariant => $this->value > 0] class Test { public $value = 100; public function foo($newValue) { $this->value = $newValue; } } and parser extension change the compiled source code by inserting this check into methods: [Contract::Invariant => $this->value > 0] class Test { public $value = 100; public function foo($newValue) { $this->value = $newValue; assert($this->value > 0); // Inserted by parser extension (via opcodes) } } Is it possible to do this? --bcaec53d5507d9343b050e56a478--