What is the difference between a language construct and a “built-in” function in PHP ? - GeeksforGeeks

26 Feb, 2019
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 unsetfunction */  $arr = array(    "1" => "Amit",    "2" => "Rajeev",    "3" => "Mohit",    "4" => "Manoj");  // Use unset function to// unset elementunset($arr["2"]);  // Display array elementprint_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

Picked
Difference Between
PHP
PHP Programs
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
Difference Between Method Overloading and Method Overriding in Java
Difference between Prim's and Kruskal's algorithm for MST
Difference between Internal and External fragmentation
Difference between Compile-time and Run-time Polymorphism in Java
How to execute PHP code using command line ?
How to Insert Form Data into Database using PHP ?
PHP in_array() Function
How to convert array to string in PHP ?
How to delete an array element based on key in PHP?