On 12/09/06, Terje Slettebø <[EMAIL PROTECTED]> wrote:
function f(Something $value)  /** @return SomethingElse */
{
  // ...
}


One of the good things about PHP is the loose typing (1.00 == 1 == "1"
sort of thing as I understand it). This has been useful.

But one of the first things we are told about using PHP ITRW is to
always validate user input and to make sure you only accept what you
know to be valid data.

More often than not, this ends up casting the data to a specific type
(number of payments - int, date of birth - date, email address -
string (or user type of email), delete - Boolean). You may even have
functions which require/expect a parameter to be of a specific type.

We can already use type hinting for arrays and classes for parameters.
Type hinting could be extended to all types for user functions. Even
the possibility of accepting multiple types for a single parameter
could be used to support a mixed type.

Recently we had a discussion about parameter overloading on methods.
You can probably use __magic to produce the effect of parameter
overloading.


Whilst casting the return type is easy to do, having the return type
as part of the function declaration would be very useful for
auto-documentors.

As for syntax, I would go with ...

type function f(type $value)

It would be useful to also have VOID as a return type, but that may be
open for discussion.


But mixed type returns (normal type -string/int/real/Boolean - for
valid results AND Boolean False for failure) would need to be
considered.




--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&amp;r=213474731
"Standing on the shoulders of some very clever giants!"

Reply via email to