On 29/04/16 16:42, Rowan Collins wrote:
> function foo($a) {
> if ( $a < 42 ) { throw new Exception; } // Must not reach The Answer
> ...
> }
> 
> vs
> 
> <<test($a < 42)>> // Must not reach The Answer
> function foo($a) { ... }

The first version is my current code base, although it's unlikely to
throw an exception, more likely to have already validated the data
before using it so the check is redundant as it is already in the code
to handle the problem data. But in the second example just where does
the error redirect traffic? At least with in-line checks you control
flow ... but just how do you add a range? Does that need different
'test' elements?

My main target here IS to add a reliable mechanism to allow every
variable to have it's own validation attributes. The only current route
is as php-annotations nicely provided and which dovetails nicely into
the existing documentation process. Simply adding comments in line is
useless for the on-line documentation, and it's adding these annotations
to the documentation in parallel with making the data available in the
code which I'm trying to address. TRYING to find this even if it is
commented in the code on 15 year old code is a problem, and being able
to ADD docBloc annotation which can then be used later provides a
practical way forward.

I've no problem with an alternate annotation method ... as long as in
PHP7 it is optional ... but I don't think this 'in-line' approach is
ACTUALLY the right long term solution to data validation.

-- 
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to