Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82426 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32724 invoked from network); 11 Feb 2015 07:07:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Feb 2015 07:07: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.172 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.172 mail-vc0-f172.google.com Received: from [209.85.220.172] ([209.85.220.172:42717] helo=mail-vc0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AB/36-33902-1CFFAD45 for ; Wed, 11 Feb 2015 02:07:46 -0500 Received: by mail-vc0-f172.google.com with SMTP id kv7so592906vcb.3 for ; Tue, 10 Feb 2015 23:07:42 -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=GBKCFSJuxoQnijHOoplt01c7XEdn8zXY4HOnVqbR3a8=; b=kyI4xAwoNw+e3gwFnkeXT7DndaX9soV4ZswFgrWR6YyYqYJVQk7kLSzF7CC0T/SWMn t7PiV830o3oiEczrIv1XdoEbe5vMUwU2HSPeUIqy9PZ1tS+FsHZqL6xSWTkjSQDFaxWT eEr/BSBJK/ESrRGKqCXAl2Y15vN399l1NenheEVlhdnjcqbKA9q5uXwkgba4/CujPGme fEjTupS9B+lVG6eLcryPRKXYe0sV0bwvCaJcJ1PNiUWk0ByDGJ7Tc8je311o4hs3ofZ4 xGCievVY1hZt1b1lZbzLHrGb6P+kmFTy758Hl+P8SmbRPrns4+PKEebWXGDExICIxeuG B9SQ== X-Gm-Message-State: ALoCoQm4cDSQsW8LdEQECJNwuKVn0odOp/XdQoZmgsrSKus2NI8ekgtWknFdvQTK+PB3Ldp3D4Tl3PDy7epTKz60sSImyUMlXmRQjqB5nCDhkQ3uS9v904F7wI+sFBPKos+HLFJeNCZo5JMyadwGo49ZAHarS4Y0tQ== MIME-Version: 1.0 X-Received: by 10.52.103.75 with SMTP id fu11mr15066956vdb.5.1423638462659; Tue, 10 Feb 2015 23:07:42 -0800 (PST) Received: by 10.52.74.73 with HTTP; Tue, 10 Feb 2015 23:07:42 -0800 (PST) In-Reply-To: References: <54D7ED22.3080001@gmail.com> Date: Wed, 11 Feb 2015 11:07:42 +0400 Message-ID: To: Yasuo Ohgaki Cc: Joe Watkins , Patrick Schaaf , internals Content-Type: multipart/alternative; boundary=047d7b86d990db1829050ecaa8ae Subject: Re: [PHP-DEV] Design by Contract From: dmitry@zend.com (Dmitry Stogov) --047d7b86d990db1829050ecaa8ae Content-Type: text/plain; charset=UTF-8 Got it, but currently we don't declare internal classes/interfaces in PHP. We do it with internal C API, of course we may extend it to support contracts, but it looks too complex for C. It's easier to make all necessary validation directly in C code. I don't think we should propose something related now. Thanks. Dmitry. On Wed, Feb 11, 2015 at 6:01 AM, Yasuo Ohgaki wrote: > Hi Dmitry and Joe, > > On Wed, Feb 11, 2015 at 6:29 AM, Yasuo Ohgaki wrote: > >> On Tue, Feb 10, 2015 at 8:53 PM, Dmitry Stogov wrote: >> >>> You are welcome to edit https://wiki.php.net/rfc/dbc2 >>> It looks like we have similar views, so just make it better in a way you >>> think. >>> >> >> Looks good to me. It's much better than original. Thank you folks. >> We have related issue like how internal module incorporate with DbC. >> However >> these could be future issues. >> > > I would like explain one of the reason why I bring up internal module. > > http://php.net/manual/en/class.sessionhandlerinterface.php > > Session has internal interface definitions like > > SessionHandlerInterface { > /* Methods */ > abstract public bool close ( void ) > abstract public bool destroy ( string $session_id ) > abstract public bool gc ( string $maxlifetime ) > abstract public bool open ( string $save_path , string $name ) > abstract public string read ( string $session_id ) > abstract public bool write ( string $session_id , string $session_data ) > } > > but it should be like follows to be precise. > > SessionHandlerInterface { > /* Methods */ > abstract public bool close ( void ) > return($ret, is_bool($ret)); > > abstract public bool destroy ( string $session_id ) > require(strlen($session_id) > 0) > return($ret, is_bool($ret)); > > abstract public bool gc ( string $maxlifetime ) > require($maxlifetime >= 0) > return($ret, is_int($ret) && $ret >= -1); > > abstract public bool open ( string $save_path , string $name ) > require(is_string($save_path)) > require(is_string($name)); > return($ret, is_bool($ret)); > > abstract public string read ( string $session_id ) > require(strlen($session_id) > 0) > return($ret, is_bool($ret) || is_string($ret)); > > abstract public bool write ( string $session_id , string $session_data ) > require(is_string($session_id) && strlen($session_id) > 0) > require(is_string($session_data)) > return($ret, is_bool($ret)); > } > > This definition is more user friendly. There were too many user save > handlers > that do not return proper values because of current interface limitation. > > Scalar type and return type hint helps, but it does not cover > > return($ret, is_int($ret) && $ret >= -1); > > for example. > > If you think this is easy to implement and should be in the RFC, I would > appreciated it > and use it to raise assertion errors just like user class/interface. > > BTW, these restrictions are coded as error in current session module and > should > be checked by the module always. It's not mandatory for the RFC, but just > a missing piece. > > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > > --047d7b86d990db1829050ecaa8ae--