By default php returns NULL for function that doesn’t do anything.
For example:
1 <?php
2
3 function foo() {
4 // Nothing here
5 }
6
7 var_dump(foo()); // the result will be NULL
I’m trying to implement an function that will have direct output and i don’t need to return anything from inside the function, i what to obtain something like:
void var_dump()// it just only dumps information.
My function will generate a image but will not return any information. The image will be generated, after processing, using ImageJpeg($image) inside the function. The signature in php manual for imageJpeg is:
imagejpeg — Output image to browser or file
in this way I’ll have output image and NULL returned from function. How can i avoid that. How can i obtain ONLY output image?
Thank you in advance.
The PHP equivalent of a
void function foo()is a regular function that simply has noreturnstatement. Whether this function outputs anything or not is completely independent of that. A function may output something in any variety of ways andreturna value, or either or neither. In concrete terms, this is a function with no return value which outputs an image:What you may be confusing here is the difference between a return value and output. The output is what the program finally outputs to the user/stout/
php://output. A function return value is what the function returns to the caller.This function visibly prints “Hello World” on your screen followed by some binary image. The function returns the string
'foo'and the variable$barnow holds'foo', but this is not output.