Page 1 of 1
language construct vs. function
Posted: Wed Nov 26, 2008 1:40 pm
by maingroup
how can I tell xxx() is a language construct or a function? So far the answers I have got are all false.
False answer 1.
functions all have return values, language constructs don't have return values.
False. language constructs can return values sometime. example: print()
False answer 2.
A pair of () is must have for functions, a pair of () is optional for language constructs.
False. a pair of () is optional in some language constructs such as print, echo. But a must have in others such as isset().
Answer 3.
Language constructs don't have understore _ in their names. True or False??
Is gettype a language construct or function? How can you tell?
Re: language construct vs. function
Posted: Wed Nov 26, 2008 1:48 pm
by Eran
Not sure where you're getting at. () indicate function parameters always. {} signifies language constructs. print() is a function not a language construct.
This of course is true for PHP only, I'm not sure if you are asking a more general programming question (which is not really relevant anyways, since different languages have different implementations of operators).
Re: language construct vs. function
Posted: Wed Nov 26, 2008 1:54 pm
by maingroup
yes, it was a php question. how can you tell foo() is a PHP language construct or a PHP function?
Re: language construct vs. function
Posted: Wed Nov 26, 2008 1:57 pm
by Eran
what do you mean by language constructs? an inbuilt language function? an inbuilt function is the same as a user defined one. Usually language constructs refers to syntax, and not functions. The concept of a function might be considered a language construct, but specific functions are implementation not constructs of the language. foo() will always be a function.
Re: language construct vs. function
Posted: Wed Nov 26, 2008 2:41 pm
by Mark Baker
maingroup wrote:how can I tell xxx() is a language construct or a function? So far the answers I have got are all false.
The easiest way is to read the manual, that will give you the correct answer every time.
This sounds like a homework question to me
Re: language construct vs. function
Posted: Wed Nov 26, 2008 2:50 pm
by John Cartwright
pytrin wrote:what do you mean by language constructs? an inbuilt language function? an inbuilt function is the same as a user defined one. Usually language constructs refers to syntax, and not functions. The concept of a function might be considered a language construct, but specific functions are implementation not constructs of the language. foo() will always be a function.
while, if, require, include, echo, return, list, etc, are all examples of language constructs (not to be mistaken with functions)
I don't think there is a rule to determine whether it is a language construct. They cover many different purposes. But as Mark Baker pointed out, the manual knows all.
Re: language construct vs. function
Posted: Wed Nov 26, 2008 3:06 pm
by Eran
Though some of those constructs you mention don't require the () operator, you are right. And it does sound like a homework assignment ..
Re: language construct vs. function
Posted: Wed Nov 26, 2008 3:18 pm
by Christopher
maingroup wrote:how can I tell xxx() is a language construct or a function? So far the answers I have got are all false.
http://us2.php.net/manual/en/function.f ... exists.php
Re: language construct vs. function
Posted: Wed Nov 26, 2008 9:02 pm
by maingroup
thanks you answered my question. if the arg is a function, function_exists() returns 1. If the arg is a language construct, it returns nothing.
Learning something new every day
