RE: [PHP-DEV] Type hints with null default values
| From: | Robert Silva | Date: | Tue, 19 Oct 2004 02:35:00 +0000 |
| Subject: | RE: [PHP-DEV] Type hints with null default values | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13381@lists.php.net to get a copy of this message | ||
I think an interface would be more appropriate than allowing multiple class
types. Null would be an implied value and you cant really type hint scalars
due to php's dynamic type system.
If both classes don't subscribe to a defined interface, then all the code
you would have to write to handle them would be no different than if you
didn't specify the type hint in the first place.
Bob
-----Original Message-----
From: Robert Cummings [mailto:robert@interjinn.com]
Sent: Monday, October 18, 2004 7:33 PM
To: Robert Silva
Cc: internals@lists.php.net
Subject: RE: [PHP-DEV] Type hints with null default values
On Mon, 2004-10-18 at 22:09, Robert Silva wrote:
> Based on the issues you listed, how about:
>
> function Method((MyClass) $obj);
> function Method([MyClass] $obj);
>
> Surrounding the class type in () or [] thereby marking it as optional.
> Much like you would do when commenting a function to take an optional
> parameter.
I like this idea and just for the sake of consideration and to elaborate
on it:
function Method( [MyClass,YourClass,null,bool] $obj );
which would allow all of the above types as values for $obj. Which would
allow a great deal of flexibility while retaining a good deal of
readability.
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'