How to use void functions in PHP

1 Answer

0 votes
class Test {
    public function __construct () {}
  
    // In PHP a void function must not return a value
    public function f () :void {
  	    echo "void function";
  	    
  	    // Fatal error: A void function must not return a value in main.php on line 9
  	    // return 5; 
    }
}

$obj = new Test;
  
echo $obj->f();



/*
run:

void function

*/

 



answered Sep 13, 2024 by avibootz

Related questions

1 answer 179 views
179 views asked Oct 13, 2016 by avibootz
3 answers 261 views
2 answers 1,321 views
8 answers 571 views
...