468,316 Members | 1,925 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,316 developers. It's quick & easy.

Type of Data Returned by a Function

I've noticed that some code analyzers comment that the type of data
returned by my functions is "unknown" in the following syntax:

function fnFooBar($aryParameters) {
$bRetVal = True;
return $bRetVal;
}

I *think* I can specify that by doing something like this:

function fnFooBar($aryParameters) bool {
$bRetVal = true;
return $bRetVal;
}

Is this correct?
If so, is there a performance gain, or is it just clean coding?
Jul 20 '07 #1
2 1167
On Jul 20, 6:32 pm, Sanders Kaufman <bu...@kaufman.netwrote:
I've noticed that some code analyzers comment that the type of data
returned by my functions is "unknown" in the following syntax:

function fnFooBar($aryParameters) {
$bRetVal = True;
return $bRetVal;

}

I *think* I can specify that by doing something like this:

function fnFooBar($aryParameters) bool {
$bRetVal = true;
return $bRetVal;

}

Is this correct?
If so, is there a performance gain, or is it just clean coding?
You think you can? Did you even try it? If you did you'd quickly
find that you get a syntax error.

That syntax isn't supported by PHP, and, as far as I know, there is no
way to specify the type of data returned. As such, I'm not sure what
your code analyzer expects you to do about it or why it would complain
about it in the first place.

Jul 21 '07 #2
Sanders Kaufman wrote:
function fnFooBar($aryParameters) bool {
$bRetVal = true;
return $bRetVal;
}

Is this correct?
No -- PHP doesn't have any method for declaring a function's return type.
(As of PHP 5 there is a limited facility for declaring the types of
parameters a function accepts, but still nothing for the return type.)

Your "code analyzers" might be able to determine return type using a
phpDoc-style comment. (Google: phpDoc.)

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 30 days, 5:45.]

Parsing an HTML Table with PEAR's XML_HTTPSax3
http://tobyinkster.co.uk/blog/2007/0...table-parsing/
Jul 21 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by DaKoadMunky | last post: by
100 posts views Thread by E. Robert Tisdale | last post: by
1 post views Thread by Ravi | last post: by
7 posts views Thread by Arpan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.