Hi, Lazare

This is something not obvious, at least for me, and should be handled in
the function itself.

Here it would be better to update the function *add()* that you could also
pass mixed and it will try to generate a *DateInterval *out of that or
whatever.
But that's another RFC.

Type-juggling applies just to weak-types like string, int, float and
boolean. I don't like to have this for resource, array or class excepted
they are compatible to each other (like array and SplFixedArray,
SplObjectStorage, ArrayIterator, ...)
If you have to do something special to get the expected type (like creating
a new object) type-juggling would not be the good-way to go.

Bye
Simon

2012/3/4 Lazare Inepologlou <linep...@gmail.com>

> >
> > I wouldn't want people to put class typehints in there such as
> >
> function foo( (SomeClass) $foo)
> >
>
> Why not? I would definitely like something like that, in the future. Here
> is an example:
>
> class DateTime {
>  ...
>  public function add( (DateInterval) $interval ) { ... }
>  ...
> }
> $date = new DateTime;
> $date->add( 'P3D' ); // string to DateInterval casting
> $date->add( 3600 );  // int (seconds) to DateInterval casting
>
> Personally, I find this to be much closer to free type-juggling PHP style
> than the current implementation with type hints (
> http://www.php.net/manual/en/datetime.add.php).
>
> [ Actually, I would prefer even type hints to work like this. Check if the
> passed argument if of the correct type and, if not, try to cast it. Failure
> to do so will lead to the E_RECOVERABLE_ERROR as today. ]
>
>
> Lazare INEPOLOGLOU
> Ingénieur Logiciel
>
>
> 2012/3/4 Paul Dragoonis <dragoo...@gmail.com>
>
> > Can you make sure that only scalar or array casts can be done?
> >
> > I wouldn't want people to put class typehints in there such as
> > function foo( (SomeClass) $foo)
> >
> > - Paul.
> >
> > On Sun, Mar 4, 2012 at 1:28 AM, Anthony Ferrara <ircmax...@gmail.com>
> > wrote:
> > > Hey all,
> > >
> > > I've drafted an RFC for the Parameter type casting hint proposal that
> > > I posted to before.  Attached to the RFC is a patch that's proposed
> > > for inclusion in core for functionality (it doesn't include news
> > > entries, or documentation, or any of the other steps that would be
> > > needed prior to commit).
> > >
> > > https://wiki.php.net/rfc/parameter_type_casting_hints
> > >
> > > Please provide feedback here on the implementation and RFC topics.
> > >
> > > Thanks,
> > >
> > > Anthony
> > >
> > > --
> > > 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
> >
> >
>

Reply via email to