Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100429 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8604 invoked from network); 7 Sep 2017 04:27:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Sep 2017 04:27:25 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@ohgaki.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@ohgaki.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ohgaki.net designates 180.42.98.130 as permitted sender) X-PHP-List-Original-Sender: yohgaki@ohgaki.net X-Host-Fingerprint: 180.42.98.130 ns1.es-i.jp Received: from [180.42.98.130] ([180.42.98.130:58784] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5D/FB-10715-5AAC0B95 for ; Thu, 07 Sep 2017 00:27:22 -0400 Received: (qmail 13856 invoked by uid 89); 7 Sep 2017 04:27:13 -0000 Received: from unknown (HELO mail-io0-f177.google.com) (yohgaki@ohgaki.net@209.85.223.177) by 0 with ESMTPA; 7 Sep 2017 04:27:13 -0000 Received: by mail-io0-f177.google.com with SMTP id i14so1574857ioe.2 for ; Wed, 06 Sep 2017 21:27:13 -0700 (PDT) X-Gm-Message-State: AHPjjUhNaJtRt+tyx1fEq9OHM3WkDWrrONLl3jrXkqzFTUn47LjU+tS8 yblgTp0KIJGeLge0PbLVZxMMzJ3hZw== X-Google-Smtp-Source: AOwi7QAKcNkqCOyASK0Z8eHzvZgjOdtoxMal4rBe4md9wh0KJ1I2i9yrCvowX5yCQWK5AyqAZpyC+u2v4O26ggU1At4= X-Received: by 10.107.128.90 with SMTP id b87mr1762131iod.334.1504758427767; Wed, 06 Sep 2017 21:27:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.72.5 with HTTP; Wed, 6 Sep 2017 21:26:26 -0700 (PDT) In-Reply-To: References: <0C7F986C-B0BC-4315-98ED-B4FD003B9399@gmail.com> <2a4491b4-e6f5-4297-beec-363f373a93e6@lsces.co.uk> <3f8be7b1-0e59-21c6-4fe8-8299b2c05645@rhsoft.net> <6ba62d62-f1ab-9e7b-93f0-a1a9238c47a6@lsces.co.uk> <0db9cfa3-2b31-ee41-713c-889b7cc06406@lsces.co.uk> Date: Thu, 7 Sep 2017 13:26:26 +0900 X-Gmail-Original-Message-ID: Message-ID: To: Dan Ackroyd Cc: Rowan Collins , PHP internals Content-Type: multipart/alternative; boundary="001a113fb3288f5891055891df78" Subject: Re: [PHP-DEV] A validator module for PHP7 From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a113fb3288f5891055891df78 Content-Type: text/plain; charset="UTF-8" Hi Dan On Wed, Sep 6, 2017 at 8:38 PM, Dan Ackroyd wrote: > On 6 September 2017 at 12:15, Rowan Collins > wrote: > > > If you have suggestions for how the format should look > > Don't use a format. Just write code - see below. > > > Which is why Yasuo and I have both suggested we work together > > If you're going to work together and continue the conversation, please > can you move this conversation elsewhere? > > It doesn't appear to be actually anything to do with PHP internals. > > On 4 September 2017 at 07:33, Yasuo Ohgaki wrote: > > > > Since I didn't get much feedbacks during the RFC discussion, I cannot > tell > > what part is disliked. > > Yes you did. You got feedback during the discussion and also during > the vote. For example: http://news.php.net/php.internals/95164 > > However you continually choose to ignore that feedback. > > I will attempt once more, to get the main point through to you. > Perhaps a small amount of repetition, will get it through: > > This type of library should be done in PHP, not in C. > This type of library should be done in PHP, not in C. > This type of library should be done in PHP, not in C. > This type of library should be done in PHP, not in C. > This type of library should be done in PHP, not in C. > This type of library should be done in PHP, not in C. > This type of library should be done in PHP, not in C. > This type of library should be done in PHP, not in C. > This type of library should be done in PHP, not in C. > This type of library should be done in PHP, not in C. > This type of library should be done in PHP, not in C. > > cheers > Dan > Ack > > > function validateOrderAmount($value) : int { > $count = preg_match("/[^0-9]*/", $value); > > if ($count) { > throw new InvalidOrderAmount("The order value must contain > only digits."); > } > > $value = intval($value); > > if ($value < 1) { > throw new InvalidOrderAmount("The order value must be one or > more."); > } > > if ($value >= MAX_ORDER_AMOUNT) { > throw new InvalidOrderAmount( > "Order value to big. Maximum allowed value is ".MAX_ORDER_AMOUNT > ); > } > > return $value; > } > You seems mixing up responsibility between - Input validation that should be input handling code's responsibility. - Logical validation that should be model code's responsibility . Please stick to single responsibility principle that you should be well aware of. Input handling code should only accepts valid inputs and let other codes use it. Other responsibilities are not input handling code's responsibilities. Your example code should be in logic, not input handling, that is written by PHP script. As I wrote in README.md, there are only 3 types of inputs. 1. Valid data should accepted. 2. Valid data should accepted, but user's mistake. e.g. Logical error like your example above. 3. Invalid. Anything other than 1 and 2 (i.e. Client cannot send these value) "validate" module is supposed to take care 3 which is nothing to do with models, etc. It should validate against input data spec, not logical meaning of the input. If programmer did this, single responsibility principle is broken. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a113fb3288f5891055891df78--