Re: [RFC][VOTE] Add validation functions to filter module
| From: | Christoph M. Becker | Date: | Thu, 08 Sep 2016 21:56:31 +0000 |
| Subject: | Re: [RFC][VOTE] Add validation functions to filter module | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-95811@lists.php.net to get a copy of this message | ||
On 08.09.2016 at 23:47, Yasuo Ohgaki wrote:
> On Thu, Sep 8, 2016 at 8:08 PM, Lester Caine <lester@lsces.co.uk> wrote:
>
>> On 08/09/16 10:02, Rowan Collins wrote:
>>
>>> No, I'm suggesting something like:
>>>
>>> if (
>>> ! validate_int($var, $min, $max)
>>> || ! validate_bool($var, $allowed_bool_types)
>>> || ! validate_string($var, $min_len, $max_len)
>>> || ! validate_string_encoding($var, $encoding)
>>> || ! validate_string_chars($var, $allowed_chars)
>>> || ! validate_string_regex($var, $regex)
>>> || ! validate_string_degit($var, $min_len, $max_len)
>>> || ! $callback($var) // Note: no need to wrap this callback, it's
>>> just a boolean-returning function
>>
>> And I am looking for some way of packaging that into something I can
>> read and write dynamically for each $var ...
>>
>> $var->set_validation_rules($rules); And $rules is going to be an array
>> of items which can then be used for related parallel activities such as
>> populating the browser validation.
>>
>> So the above script is replaced by $var->is_valid(); or if you prefer it
>> throws an exception when you try and set the variable with an invalid
>> input ( or one that does not match a 'strict' rule ).
>
> Anyway, your way would work with autoboxing.
> https://wiki.php.net/rfc/autoboxing
> and this proposal.
And it can even work without autoboxing; just wrap the scalars in
objects manually.
--
Christoph M. Becker