Home > Archive > PHP Language > October 2006 > similar at function_exist but if function_has_values
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
similar at function_exist but if function_has_values
|
|
|
| I want to verified when one function myFunction return a value (link).
The function can return a string (link) or nothing.
If I want know if function exist I can write this
if function_exist(myFunction) ...
now I want know if the return of the function is some or nothing:
if function_has_value(myFunction)
{... code }
or similar
if funtion_return_value(myFunction)
{... code }
or
if function_not_return_no_value(myFunction)
{... code }
how I can resolve?
| |
|
| artev wrote:
> I want to verified when one function myFunction return a value (link).
> The function can return a string (link) or nothing.
>
>
> If I want know if function exist I can write this
> if function_exist(myFunction) ...
>
> now I want know if the return of the function is some or nothing:
>
> if function_has_value(myFunction)
> {... code }
> or similar
> if funtion_return_value(myFunction)
> {... code }
> or
> if function_not_return_no_value(myFunction)
> {... code }
>
>
> how I can resolve?
Not easily, wether a function returns something is often dependant on the
input (allthough more user-defined functions should return false/thrigger
an error, often forgotten/skipped by most people).
If you know the function name, and the parameters, you can offcourse:
$returns_something =
is_null(call_user_func($name,$parameter1
[,$parameter2[,..]]));
Allthough, when it returns null (which is rare), it will say the function
returns nothing).
--
Rik Wasmus
| |
|
| -Code for test-
<?php function test($aa)
{
if (is_null($aa))
print 'I AM NULL';
else
print 'NO';
}
?>
<?php test( my_function(par1; par2, par3) ); ?>
-Code normal--
<?php my_function(par1; par2, par3); ?>
While the code normal write link or nothing the code test,
write always I AM NULL;
-----------------
If I use this code:
if (is_string($aa))
print 'I AM STRING';
else
print 'NO';
write always NO:
So when I have a link the test said: isn't a string and is null;
When I have nothing the test said: isn't a string(exact) and is null
(exact);
| |
|
| -Code for test-
<?php function test($my_fun)
{
if (is_null($my_fun))
print 'I AM NULL';
else
print 'NO';
}
?>
<?php test( my_function(par1; par2, par3) ); ?> (point A)
-Code normal--
<?php my_function(par1; par2, par3); ?>
While the code normal write link or nothing the code test,
write always I AM NULL;
-----------------
If I use this code:
if (is_string($my_fun))
print 'I AM STRING';
else
print 'NO';
write always NO:
So when I have a link the test said: isn't a string and is null;
When I have nothing the test said: isn't a string(exact) and is null
(exact);
AND OTHER PROBLEM:
in the code test the point A repeat the value of the my_function:
I not want that; I want only use the if (is_null($my_fun))
and not the value of $my_fun
..
|
|
|
|
|