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

From: Date: Tue, 06 Nov 2007 17:00:46 +0000
Subject: A workaround for type hinting native types (and a little of self-advertising)
Groups: php.general 
Request: Send a blank email to php-general+get-264125@lists.php.net to get a copy of this message
$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@test.com', ...); EXAMPLE; echo "Regards, \n Martin Alterisio";

« previous php.general (#264125) next »