Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83887 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79939 invoked from network); 26 Feb 2015 11:09:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2015 11:09:47 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.177 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.177 mail-vc0-f177.google.com Received: from [209.85.220.177] ([209.85.220.177:37015] helo=mail-vc0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/B2-65287-BFEFEE45 for ; Thu, 26 Feb 2015 06:09:47 -0500 Received: by mail-vc0-f177.google.com with SMTP id hy10so3590202vcb.8 for ; Thu, 26 Feb 2015 03:09:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=76eD4WBfVKnHjXqnzAnQhmKoOwdmrl84zX/Vtx6SAk0=; b=lIh97Q8gQLcS3eX1xUZlpF+ureDrzRzmtgFtsZZTw1bZcm9ZVK1b/jXDUHIzB5kZzp PRSxa4NgdYW7pTJF9ndugRqP2ggpORT+Px5oqzPEmRFBqGAKLQCT2zMnE9uJxF1ghT0Y 9tXw/GRvaa448N77pmoLt8BOC+VLn1YIj/+xEltnBmR+XiLW0qpeDGruJM+1GyF1wOY1 tG67AteEDUJusE3PUv//apnUOINeWaut35RLgV3kvyV5/+xR9Y+xAY7jiGZK5KJFEcJa lp+z92D0X9836bFEm5PFcXhpG8eNLSN9VxqykSQa2HUbTqzH1gwzHsqTTmkgwy0NNaOB kbEw== X-Gm-Message-State: ALoCoQk+eqjAnNz1Vy+KmJGsPkdB664MnrlrXdfM5AZxftxBmmld1YyxpWpDmkPIALWQuFkQ9s197xzwoARFtVUga8/iANt9phXO+rCRQelc0qNROhufrOkwd6NqDyNE47cuWyx9dILHc14b9IQ0Npn9NGNK3a22aw== MIME-Version: 1.0 X-Received: by 10.53.11.76 with SMTP id eg12mr8227627vdd.68.1424948984740; Thu, 26 Feb 2015 03:09:44 -0800 (PST) Received: by 10.52.113.231 with HTTP; Thu, 26 Feb 2015 03:09:44 -0800 (PST) In-Reply-To: References: Date: Thu, 26 Feb 2015 15:09:44 +0400 Message-ID: To: Joe Watkins Cc: Benjamin Eberlei , Anthony Ferrara , PHP Internals Content-Type: multipart/alternative; boundary=001a1133f0560f1268050ffbcaa4 Subject: Re: [PHP-DEV] Strict typing and callback vs declare() From: dmitry@zend.com (Dmitry Stogov) --001a1133f0560f1268050ffbcaa4 Content-Type: text/plain; charset=UTF-8 On Thu, Feb 26, 2015 at 1:43 PM, Joe Watkins wrote: > > The implementation should be simpler and more efficient than using > declare(). > > This can't really be correct, if a call to > > function mine(int $one, double $two) { > > } > > results in three function calls then that's going to cost considerably. > No. The callback is going to be called only when expected and passed types are different (e.g. passing "123" to int; or 1 to bool) It must be relatively seldom. > > I don't like the idea of user function being called, but don't hate the > idea of an internal > API that allows an extension to implement a type system. > > It could be much simpler, like turning zend_verify_arg_type into a pointer > to a function like > we did with gc function. > > All of this is inferior to dual mode, in my opinion. > Implementing, strict types in extension is an option. but I think it won't satisfy the strict camp. User callback is a tool that doesn't change the mainstream language semantic, but provides a way to analyze strict type inconsistencies. Thanks. Dmitry. > > Cheers > Joe > > On Thu, Feb 26, 2015 at 10:34 AM, Benjamin Eberlei > wrote: > >> On Thu, Feb 26, 2015 at 11:10 AM, Dmitry Stogov wrote: >> >> > Hi Anthony, >> > >> > What do you think about using a user level callback for strict type >> checks >> > instead of declare(). It won't allow changing behavior per file, but >> this >> > has its own cons and pros. >> > >> > > > set_strict_type_checker(function ($class_name, $function_nume, $arg_num, >> > $expected_type, $value, $file, $line) { >> > ... >> > return false; >> > }); >> > include("orig_index.php"); >> > ?> >> > >> > If callback is not set, arguments are converted according to standard >> > rules, if set and returns false - fatal error or exception is thrown. >> > >> > The implementation should be simpler and more efficient than using >> > declare(). >> > >> > Thanks. Dmitry. >> > >> >> This ruins portability with third party libraries completely. >> > > --001a1133f0560f1268050ffbcaa4--