From: Nathan Rixham on
tedd wrote:
> At 3:17 PM +0100 2/23/10, Daniel Egeberg wrote:
>> 2010/2/23 Dasn <dasn(a)lavabit.com>:
>> > Could you tell me how to retrieve the 'return type'?
>>> Thanks.
>>>
>>>
>>> --
>>> Dasn
>>
>> That's not possible. Consider this function:
>>
>> function foo()
>> {
>> switch (rand(0, 1)) {
>> case 0: return 42;
>> case 1: return 'bar';
>> }
>> }
>>
>> What should the return type be?
>>
>> --
>> Daniel Egeberg
>
>
> It can be anything you want to test for -- check out:
>
> is_int();
> is_nan();
> is_float();
> is_long();
> is_string();
>
> IOW, is_whatever();
>
> Cheers,
>
> tedd
>

As PHP is loosely typed, the only real way around this is to specify a
return type in a PHPDoc block, then parse that using reflection to get
the @return parameter.

another option is to use something like haXe which is an ECMA style
typed language that compiles to multiple targets, one of which is PHP.

Regards!

Nathan

From: Ashley Sheridan on
On Tue, 2010-02-23 at 09:31 -0500, tedd wrote:

> At 3:17 PM +0100 2/23/10, Daniel Egeberg wrote:
> >2010/2/23 Dasn <dasn(a)lavabit.com>:
> > > Could you tell me how to retrieve the 'return type'?
> >> Thanks.
> >>
> >>
> >> --
> >> Dasn
> >
> >That's not possible. Consider this function:
> >
> >function foo()
> >{
> > switch (rand(0, 1)) {
> > case 0: return 42;
> > case 1: return 'bar';
> > }
> >}
> >
> >What should the return type be?
> >
> >--
> >Daniel Egeberg
>
>
> It can be anything you want to test for -- check out:
>
> is_int();
> is_nan();
> is_float();
> is_long();
> is_string();
>
> IOW, is_whatever();
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com http://ancientstones.com http://earthstones.com
>


is_quantum() is pretty useful as well, if you want to see if it's sort
of there and not at the same time. Probably turns into a cat in a box at
some point too, everything quantum has cats in...

Thanks,
Ash
http://www.ashleysheridan.co.uk


From: Kevin Kinsey on
Ashley Sheridan wrote:
> is_quantum() is pretty useful as well, if you want to see if it's sort
> of there and not at the same time. Probably turns into a cat in a box at
> some point too, everything quantum has cats in...
>
> Thanks,
> Ash

So, should we add to the list:

is_schrodingers_cat_alive()

??

KDK
From: Ashley Sheridan on
On Tue, 2010-02-23 at 19:19 -0600, Kevin Kinsey wrote:

> Ashley Sheridan wrote:
> > is_quantum() is pretty useful as well, if you want to see if it's sort
> > of there and not at the same time. Probably turns into a cat in a box at
> > some point too, everything quantum has cats in...
> >
> > Thanks,
> > Ash
>
> So, should we add to the list:
>
> is_schrodingers_cat_alive()
>
> ??
>
> KDK
>


I think PHP would crash trying to return the boolean value from that
one!

Thanks,
Ash
http://www.ashleysheridan.co.uk


From: Dasn on
On Tue, 23 Feb 2010 23:44:17 +0800, Nathan Rixham wrote:


>
> As PHP is loosely typed, the only real way around this is to specify a
> return type in a PHPDoc block, then parse that using reflection to get
> the @return parameter.
>
> another option is to use something like haXe which is an ECMA style
> typed language that compiles to multiple targets, one of which is PHP.
>

Thanks Nathan for your comment. But I think the PHPDoc stuff is only for
user defined functions, right? The Reflection::getDocComment() has no idea
about the built-in functions.

--
Dasn