Re: Using function prototypes in code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 9, 2011 at 6:10 PM, Frank Thynne <frank.thynne@xxxxxxxxx> wrote:

> function integer int_func(string $s) {
>  // does something like, say, converting "five" to 5
> }
>

As Stuart pointed out, type-hinting currently only works for classes and
arrays. Scalar type-hinting is planned for the future, but for now you're
left with enforcing it in the function itself. You can create a class with
static helpers to make this easier if you're going to do it frequently.

As for documentation, go with the PHPDoc standard:

/**
 * Converts a spelled-out number to the equivalent integer.
 *
 * @param string $s must be a spelled out number, e.g. "five" rather than
"5".
 * @return int
 */
function int_func($s) { ... }

To confuse me a bit further, I can't find a definitive list of the
> basic type names. For example, is it "integer" or "int"?


I use "int" and "bool" with the rest spelled out which works with casting.

Peace,
David

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux