Search code examples
phpvoid

what is difference between passing void as a parameter and not passing it to function?


I got confused while reading code from php mannual --

what is difference in below two syntaxes --

final public string Exception::getMessage () 

vs

final public string Exception::getMessage ( void ) 

As Manuel says this function has no parameter, then what is purpose of passing that void there. Although void its self represent that it will be having noting. So my questions are --

1- Which one is most standard way in both syntaxes and why ?

http://php.net/manual/en/class.errorexception.php


Solution

  • void is not an actual language construct. It's just used for decorative purposes in the manual.

    See http://php.net/manual/en/language.pseudo-types.php(dead link)

    void

    void as a return type means that the return value is useless. void in a parameter list means that the function doesn't accept any parameters.

    PHP Manual, © 1997-2015 the PHP Documentation Group, CC-BY-SA 3.0