[PHP] How to get the 'return type' of a function?
Hello guys, I try to use 'ReflectionFunction' to retrieve the info of a function. For example: ?php $rf = new ReflectionFunction('strstr'); echo $rf; ? === output == Function [ internal:standard function strstr ] { - Parameters [3] { Parameter #0 [ required $haystack ] Parameter #1 [ required $needle ] Parameter #2 [ optional $part ] } } The problem is there's no 'return type' (i.e. 'string' in this example) info about the function. Could you tell me how to retrieve the 'return type'? Thanks. -- Dasn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to get the 'return type' of a function?
2010/2/23 Dasn d...@lavabit.com: Hello guys, I try to use 'ReflectionFunction' to retrieve the info of a function. For example: ?php $rf = new ReflectionFunction('strstr'); echo $rf; ? === output == Function [ internal:standard function strstr ] { - Parameters [3] { Parameter #0 [ required $haystack ] Parameter #1 [ required $needle ] Parameter #2 [ optional $part ] } } The problem is there's no 'return type' (i.e. 'string' in this example) info about the function. Could you tell me how to retrieve the 'return type'? Thanks. I think PHP doesnt support it. In ReflectionParameter class you'll see there is no parameter type too. May be this is because PHP is loosely typed language. -- Shiplu Mokaddim My talks, http://talk.cmyweb.net Follow me, http://twitter.com/shiplu SUST Programmers, http://groups.google.com/group/p2psust Innovation distinguishes bet ... ... (ask Steve Jobs the rest) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to get the 'return type' of a function?
2010/2/23 Dasn d...@lavabit.com: Hello guys, I try to use 'ReflectionFunction' to retrieve the info of a function. For example: ?php $rf = new ReflectionFunction('strstr'); echo $rf; ? === output == Function [ internal:standard function strstr ] { - Parameters [3] { Parameter #0 [ required $haystack ] Parameter #1 [ required $needle ] Parameter #2 [ optional $part ] } } The problem is there's no 'return type' (i.e. 'string' in this example) info about the function. 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to get the 'return type' of a function?
2010/2/23 Daniel Egeberg degeb...@php.net 2010/2/23 Dasn d...@lavabit.com: Hello guys, I try to use 'ReflectionFunction' to retrieve the info of a function. For example: ?php $rf = new ReflectionFunction('strstr'); echo $rf; ? === output == Function [ internal:standard function strstr ] { - Parameters [3] { Parameter #0 [ required $haystack ] Parameter #1 [ required $needle ] Parameter #2 [ optional $part ] } } The problem is there's no 'return type' (i.e. 'string' in this example) info about the function. 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? Mixed? http://www.php.net/manual/en/language.pseudo-types.php#language.types.mixed -- Daniel Egeberg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to get the 'return type' of a function?
At 3:17 PM +0100 2/23/10, Daniel Egeberg wrote: 2010/2/23 Dasn d...@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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to get the 'return type' of a function?
tedd wrote: At 3:17 PM +0100 2/23/10, Daniel Egeberg wrote: 2010/2/23 Dasn d...@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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to get the 'return type' of a function?
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 d...@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
Re: [PHP] How to get the 'return type' of a function?
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to get the 'return type' of a function?
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