language construct vs. function
Moderator: General Moderators
language construct vs. function
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?
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
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).
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
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
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.
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: language construct vs. function
The easiest way is to read the manual, that will give you the correct answer every time.maingroup wrote:how can I tell xxx() is a language construct or a function? So far the answers I have got are all false.
This sounds like a homework question to me
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: language construct vs. function
while, if, require, include, echo, return, list, etc, are all examples of language constructs (not to be mistaken with functions)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.
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
Though some of those constructs you mention don't require the () operator, you are right. And it does sound like a homework assignment ..
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: language construct vs. function
http://us2.php.net/manual/en/function.f ... exists.phpmaingroup wrote:how can I tell xxx() is a language construct or a function? So far the answers I have got are all false.
(#10850)
Re: language construct vs. function
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
Learning something new every day