What is the difference between a language construct and a “built-in” function in PHP ?
In programming, language constructs and built-in functions are often misinterpreted with one another due to the fact that both have more or less alike behavior. But they differ from each other in the way the PHP interpreter interprets them. Every programming language consists of tokens and structures which the respective language parser can recognize. So whenever a file is parsed, the parser understands their usage and knows well what to do with them without having the need to examine them further. These tokens and structures are known as language construct. They are basically keywords that are a part of the programming language. In other words, they form the syntax of the language.
Following are some examples of language constructs:
echo() include() require() print() isset() die()
Language constructs cannot be added to the PHP framework through any plugins or libraries. They may or may not return any values although most of them don’t. Also, some of them do not need the use of parenthesis.
Below examples illustrate the use of language construct in PHP:
Example 1:
<?php print('Monday '); print 'Tuesday '; $str = 'Wednesday'; echo $str; ?> |
Monday Tuesday Wednesday
Example 2:
<?php /* PHP program to use unset function */ $arr = array( "1" => "Amit", "2" => "Rajeev", "3" => "Mohit", "4" => "Manoj"); // Use unset function to // unset element unset($arr["2"]); // Display array element print_r($arr); ?> |
Array
(
[1] => Amit
[3] => Mohit
[4] => Manoj
)
On the other hand, built-in functions are blocks of code that are jotted down in such a way that they can be reused again and again in executing a specific task. They are already present in the PHP installation package. It is due to these built-in functions that PHP is an efficient scripting language.
Some common built-in functions used in PHP are:
json_encode() mail() explode() rand() curl_init()
Built-in functions are comparatively slower than their language construct counterparts. They have better code organization. They usually take input arguments and always return a value. Built-in functions usually comprise of date, numeric and string functions.
Below examples illustrate the use of built-in function in PHP:
Example 1:
<?php /* Date functions in PHP */ echo" Date and time is - "; print date("j F Y, g.i.a", time()); ?> |
Date and time is - 26 February 2019, 12.22.pm
Example 2:
<?php /* String functions in PHP */ $MyStr = "GeeksForGeeks"; echo substr("GeeksForGeeks", 5, 3)."\n"; echo trim(" GeeksForGeeks ")."\n"; echo str_replace("Geeks", "Code", "GeeksForGeeks"); ?> |
For GeeksForGeeks CodeForCode
Recommended Posts:
- Difference between while(1) and while(0) in C language
- Difference between Java and C language
- Difference between %d and %i format specifier in C language
- Difference Between Go and Python Programming Language
- Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
- builtin command in Linux with examples
- Difference between Procedural and Non-Procedural language
- What is the difference between is_a() function and instanceof in PHP?
- Difference between Method and Function in Python
- Difference between isset() and array_key_exists() Function in PHP
- Difference between function expression vs declaration in JavaScript
- Difference Between indexOf and findIndex function of array
- chdir() in C language with Examples
- Constants vs Variables in C language
- HTML | Navigator language Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



