Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating functions without parentheses in PHP like 'echo'

Tags:

php

I was wondering if there is any nice way of writing functions in PHP so that they don't require ( ) around the parameters.

Example:

function sayThis($str) {
    echo $str;
}

sayThis "hi!!";

Thanks, Matt Mueller

like image 769
Matt Avatar asked Nov 21 '09 00:11

Matt


2 Answers

There simply isn't. "echo" is more of an operator than a function, so you'd actually need to rewrite the PHP interpreter source in order to introduce new "functions" like those.

Edit: Actually, the more accurate term for "echo" is, as eyze has correctly pointed out, language construct rather than operator. http://php.net/manual/de/function.echo.php provides some more information.

like image 51
fresskoma Avatar answered Oct 20 '22 12:10

fresskoma


Simple answer, no.

echo is a language construct not a function, hence it doesn't need the parentheses.

like image 28
Alix Axel Avatar answered Oct 20 '22 11:10

Alix Axel