language construct vs. function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maingroup
Forum Newbie
Posts: 12
Joined: Thu Apr 24, 2008 2:04 pm

language construct vs. function

Post 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?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: language construct vs. function

Post 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).
maingroup
Forum Newbie
Posts: 12
Joined: Thu Apr 24, 2008 2:04 pm

Re: language construct vs. function

Post by maingroup »

yes, it was a php question. how can you tell foo() is a PHP language construct or a PHP function?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: language construct vs. function

Post 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.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: language construct vs. function

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: language construct vs. function

Post 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.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: language construct vs. function

Post 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 ..
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: language construct vs. function

Post 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
(#10850)
maingroup
Forum Newbie
Posts: 12
Joined: Thu Apr 24, 2008 2:04 pm

Re: language construct vs. function

Post 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 :)
Post Reply