Is there a possible way to combine the if function and the isset function (Or other functions) into one function.
For example:
if(isset($_GET['test'])){
echo "It exists";
}
into
exitsts($_GET['test']){
echo "It exists";
}
I searched on google and stackoverflow and used multiple ways to describe it.
But no solution.
So is there a solution for it?
Thanks in advance!
Bram Hammer
No, this is not possible. If is not a function, but a syntax element. Usually in most programming languages you have functions, which take values and return values (and maybe do something behind the back in the process) and syntax elements, which can be used to structure the code and have it behave in certain ways, for example branching (if-then-else), looping (for,while etc). The distinction in most languages is simple: If it has a block of code behind it, then it is a syntactic element, if it is somehow called, it is a function. However this may not be true for all languages.
It is usually not possible to add your own syntax elements, unless the language explicitly allows it through some meta-programming facilities, like macros or other powerful tools used to extend the language. As far as I know PHP does not offer any such tools. One way to get them for languages which do not offer them out of the box is to use an additional preprocessor, such as M4. However this is rarely useful.
Some languages also allow treating blocks of code as values, so in that case you can use functions in a similar way as syntactic elements, passing them code which has not yet been evaluated. If blocks of code cannot be directly used, maybe the language offers anonymous functions or anonymous classes, which can be used to simulate this. However usually these simulated control-structures are not nearly as nice looking as the built in control structures. I am not sure whether PHP allows anonymous functions, or classes, you may be able to build something like the structure you want, but it will look very ugly.