A workaround for type hinting native types (and a little of self-advertising)

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

 



$me->apologizeFor($this->isSelfAdvertising());
if ($you->lookingFor($php->workaround(TYPE_HINT_FOR_NATIVE_TYPES)) {
    check('http://www.phpclasses.org/browse/package/4195.html');
}

$package = new Package('http://www.phpclasses.org/browse/package/4195.html'
);

$package->usageExample = <<<EXAMPLE
    function test(int $n) {
    }
    test(1);
    test("2"); // string representation of an int is OK
    test(1.2); // not an int, fails
    // there are also type hints for strictly checking types: StrictInt,
StrictString, etc
EXAMPLE;

$package->isExtendable = true;

$package->extensionExample = <<<EXAMPLE
    final class EmailAddress implements TypeHint {
        private function __construct() { }
        public static function isTypeHintFor($value) {
            ... regexp check for $value ...
        }
    }

    sendMail(EmailAddress $email, ....) {
        ....
    }

    sendMail('test@xxxxxxxx', ...);
EXAMPLE;

echo "Regards, \n Martin Alterisio";

[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