De : Dmitry Stogov [mailto:dmi...@zend.com] 
>
> I don't like phpdoc approach because we have to define, parse and compile new 
> syntax for constraints.
> Would constraint be able to call other functions? include external php files? 
> etc?

There are 2 sort of constraints :

- declared types with a specific, while very intuitive, syntax (support for 
every current type found in phpdoc will be provided). These types will be sent 
as plain strings along with the corresponding zval argument to an internal 
validator function. This is a valuable addition compared to the DbC basic 
conditions. I gave the example of str_replace() whose search argument would 
have a type like 'string|array(string)'. Do you think that, if we implement 
such a check in PHP in an in{} block, it will be as readable ? I don't think 
so. OK, it is an addition to what other languages implement but, if we 
implement something easier and more readable, the concept is still valid.

- and assertions. An assertion line just contains a PHP expression to evaluate. 
No new syntax here, expression can do
anything, like calling an external validator function. The condition would be 
executed in the function scope, so it would have access to anything accessible 
from the function body. Exactly the same as what we would do with in/out{} 
blocks.

In my opinion, as I previously explained, constraints shouldn't be parsed by 
the PHP engine, but by a pre-processor which would run before any other action 
takes place. This pre-processor would insert some PHP code where it is needed. 
Then, the script would be compiled but the engine doesn't have to be concerned.

Cheers

François


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

Reply via email to