note 77523 rejected from language.oop5.typehinting by nlopess
| From: | nlopess@php.net | Date: | Sun, 02 Sep 2007 10:22:09 +0000 |
| Subject: | note 77523 rejected from language.oop5.typehinting by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-130100@lists.php.net to get a copy of this message | ||
Note Submitter: konstantin at boyandin dot info
----
1. It should certainly be added to the manual, that type hinting expects either the specified class,
or its derivative (subclass).
2. What disturbs me is the fact that function with type hinting is executed nonetheless, even if
type mismatch exception occurs:
<?php
$a = new B();
Test($a);
class A {
public $name = 'A';
public function show() {
print($this->name);
}
}
class B {
public $name = 'B';
public function show() {
print($this->name);
}
}
function test(A $obj) {
$obj->show();
}
?>
The code above will produce fatal error, *and* will print 'B' anyway.
Should type mismatch prevent function from execution?