Re: Re: Flexible type hinting
| From: | Stanislav Malyshev | Date: | Thu, 02 Jul 2009 15:19:47 +0000 |
| Subject: | Re: Re: Flexible type hinting | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-44664@lists.php.net to get a copy of this message | ||
Hi!
Are optional argument specifications inherited? I did not think they were, but its not clear if you are saying they are.Of course they are - how couldn't they be, they are part of method definition.
My understanding of PHP's optional arguments is that they only apply to a function once it is called.Yes, but it doesn't prevent them from being part of inheritance logic. if you have foo($a = 1) then you can't override it with foo($a) - it violates LSP (imagine somebody calling $a->foo()).
But it is called! The whole point of the interface is to call it - i.e. to have code use the fact that you can be sure to have foo(int $a) in some object of some unknown class. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.comAnd it is doing something - if you declare interface as foo(int $a) and implement it as foo(string $a) there may be a lot of WTF happening.I mean that it is never called, therefore the type hints are not checked, and this is fine.