Re: A validator module for PHP7

From: Date: Wed, 06 Sep 2017 11:38:03 +0000
Subject: Re: A validator module for PHP7
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  Groups: php.internals 
Request: Send a blank email to internals+get-100409@lists.php.net to get a copy of this message
On 6 September 2017 at 12:15, Rowan Collins <rowan.collins@gmail.com> 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 <yohgaki@ohgaki.net> 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; } (i'd probably recommend not using exceptions, but instead return [$valid, $value] to allow validating multiple items without having to use exceptions for flow control.)

« previous php.internals (#100409) next »