For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > October 2006 > other









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 other
artev

2006-10-30, 7:02 pm

If I write only this row
<?php var_dump(my_function(par1,par2,par3)); ?>

I have always the word NULL in the page,
preceded by value of the function (link)
Shaun

2006-10-30, 7:03 pm

On Tue, 24 Oct 2006 22:50:03 +0200, artev <mailnotspammm@notspamm.nn>
wrote:

>If I write only this row
><?php var_dump(my_function(par1,par2,par3)); ?>
>
>I have always the word NULL in the page,
>preceded by value of the function (link)


That's because your function is echoing or printing a value instead of
returning it. Here's a demonstration of the difference:

<?php
function my_function($foo) {
return $foo * 2;
}
var_dump(my_function(6));
?>

...prints out:

int(12)

...however,

<?php
function my_function($foo) {
echo $foo * 2;
}
var_dump(my_function(6));
?>

...prints out:

12NULL

The 12 is being printed out by the call to my_function(). The NULL is
being printed out because my_function() is not returning anything for
var_dump() to display.

hth

-
Remove mypants to email.
<http://www.shaunc.com/>
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com