RE : [PHP-DEV] RE : Namespaces and __autoload()
| From: | P) | Date: | Wed, 12 Sep 2007 13:32:13 +0000 |
| Subject: | RE : [PHP-DEV] RE : Namespaces and __autoload() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-32288@lists.php.net to get a copy of this message | ||
> From: Pawel Stradomski [mailto:pstradomski@gmail.com]
>
> B), but what with following language construct:
>
> function doSomething (Service s) {...}
>
> PHP tries to autoload type Service, but it can't know if it's
> looking for interface or class. Both are possible.
Correct. I didn't consider this case because I didn't know this syntax for interfaces.
To include this case, we can consider that, instead of a 'type' value, the __autoload
handler receives a bit mask of the four possible types that can be requested : classes,
interfaces, functions, and constants. It will have the responsibility to resolve every
types corresponding to the bits set in the mask.
In your example, the interpreter would set the class and interface bits, as it cannot
know which one it needs.
Your example seems to imply that classes and interfaces should not have the same name.
Even if it is generally the case, it is not impossible. In this case, what does your
example take, the class or the interface ?
Just an idea: wouldn't it be better to modify the syntax to :
Function doSomething (Always_A_Class s) { ... }
Function doSomething (s implements An_Interface) { ... }
And maybe
Function doSomething (s implements (Interface1,Interface2,...)) { ... }
Francois