Has type hinting for functions been implemented in ZE2?
Brian.
dealnews.com
----- Original Message -----
From: "Timm Friebe" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, March 27, 2003 10:16 AM
Subject: [PHP-DEV] Type hints revisited [IllegalArgumentException instead of
E_ERROR]
| I've implemented an additional feature for type hints that will throw an
| exception instead of bailing out in case an incorrect type is passed.
|
| Test script:
|
| <?php
| class Date { }
| class Article {
| public function setCreated_at(Date $date) {
| echo __CLASS__, '::', __FUNCTION__, ' called with ';
| var_export($date);
| echo "\n";
| }
|
| public function setLastchange([Date] $date) {
| echo __CLASS__, '::', __FUNCTION__, ' called with ';
| var_export($date);
| echo "\n";
| }
| }
|
| $a= new Article();
| $a->setLastchange(new Date());
| $a->setLastchange(NULL); // Passes
| $a->setCreated_at(new Date());
|
| try {
| $a->setCreated_at(NULL); // Fails
| } catch (IllegalArgumentException $e) {
| echo "Caught: "; var_dump($e);
| }
|
| $a->setCreated_at(1); // Fails
| echo "Alive"; // Will not show up
| ?>
|
| Output:
| ---------------------------------------------------------------------
| [EMAIL PROTECTED]:~/devel/php > ./php5/sapi/cli/php hints.php
| article::setlastchange called with class date {
| }
| article::setlastchange called with NULL
| article::setcreated_at called with class date {
| }
| Caught: object(illegalargumentexception)#2 (3) {
| ["message"]=>
| string(38) "Argument 1 must be an instance of date"
| ["file"]=>
| string(36) "/usr/home/thekid/devel/php/hints.php"
| ["line"]=>
| int(4)
| }
|
| Fatal error: Uncaught exception! in Unknown on line 0
| ---------------------------------------------------------------------
|
| A unified diff is attached.
|
| - Timm
|
----------------------------------------------------------------------------
----
| --
| PHP Internals - PHP Runtime Development Mailing List
| To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php