ZCPE 5.5 here we go – PHP Basics (Language constructs)
Zend divided language constructs in three main categories output construct, evaluation construct and others constructs, you can find this division in zend study guide for PHP 5.5 exam.
Output
Construct | Description |
---|---|
die / exit | Used to output a result and then terminate the running script |
echo / print | Used to output a result |
return | Used to halt a execution of a function or a script |
Evaluation
Construct | Description |
---|---|
empty | Used to identify if an variable is empty (without an value) |
eval | Used to evaluate string content |
include/include_once | Used to include a file (using this just a warning is thrown if the file not exists) |
require/require_once | Used to include a file (using this a fatal error is thrown) |
Others
Construct | Description |
---|---|
isset | Used to identify if a variable exists |
unset | Used to unset(“delete”) an existing variable |
list | Used to make easier to use an array values |
What is the difference?
You can argue that those language constructs are just regular functions and they haven’t anything in special, but actually they have. In PHP language constructs can be used with or without parentheses, so let’s illustrate:
<?php
require 'foo/bar.php'; //valid
require ('foo/bar.php'); //valid
Both are correct to use, but it is recommended to do not use with parentheses for the sake of good practice. Therefore we aren’t allowed to use any function provided by PHP without parentheses:
<?php
$a = [];
$b = [];
array_merge($a, $b); //valid
array_merge $a, $b; //invalid
Some posts in the internet said language constructs are faster than built-in functions, but we must remember that it is a matter of microseconds and I think it is worthless to bother about it.