What would a language constructor be in PHP? What are they?
The language constructor or reserved words are the grammars defined / used by the lexical parser to interpret a syntax. Programs such as lex / flex and yacc / bison that compose this universe of lexical analysis. For example: If you want to write a new language you will have to define which commands it accepts or not, in which order it should be written and define every detail so that the computer can interpret the commands and even know what to do when something is written in their new language.
Let's say you have defined the words ("look up" and "negatively"), these words will be reserved. the lex / flex together yacc / bison work to read these entries and generate an already optimized C code to recognize their syntax and treat it as you have defined it. The "isset" command for php is also defined in the language grammar, more specifically in the file zend_language_scanner.l source code is available if you want more information. The function "array_key_exists" is not present in the lexical constructor. It is not a reserved word for not doing the php (language) syntax, but it does exist and adds functionality to the php core and makes up the standard php module, "array_key_exists" you can find more information in " php_array.h " and " array.c ", as can be seen unlike the isset that is defaults to constructing the syntax, it is not defined in the language creation, but rather "added" "PHP_FUNCTION (array_key_exists)", just as you might could be creating a module itself and adding any other function .
You can find some token used in direct in the manual or at source code . If you wish, you can also find in the stackoverflow a post about analysis lexical also has a lot of interesting stuff about it on the internet.
Note:
lex, flex, yacc and bison are different programs. And inserted in the context just to facilitate, if you want more references on the subject
Why does the PHP documentation recommend in some cases to use language constructors instead of functions?
In the case of isset and array_key_exists the recommendation I found on the site is due to performance issues, as in the php documentation page itself, one of the suggestions is not to replace, but to use both. There is a Benchmark, showing the runtime of the algorithms.
The reason for one being faster than the other is not exclusively that one is a language constructor and another is a function, but also the complexity of the algorithms to execute an isset or an array_key_exists.
The complexity of the algorithm can cause you to gain or lose performance depending on the volume of use. As each case is a case, the ideal is to read both the documentation and the note for more information, and if there is still doubt, need and / or interest is possible to access the source code.
In isset and array_key_exists what was pointed out was the performance, but may be issues since depreciation, retro compatibility and etc ..., but I say again, each case is a case.
As a matter of curiosity this is the implementation of array_key_exists in
php 7.1
PHP_FUNCTION(array_key_exists)
{
zval *key; /* key to check for */
HashTable *array; /* array to check in */
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_ZVAL(key)
Z_PARAM_ARRAY_OR_OBJECT_HT(array)
ZEND_PARSE_PARAMETERS_END();
switch (Z_TYPE_P(key)) {
case IS_STRING:
if (zend_symtable_exists_ind(array, Z_STR_P(key))) {
RETURN_TRUE;
}
RETURN_FALSE;
case IS_LONG:
if (zend_hash_index_exists(array, Z_LVAL_P(key))) {
RETURN_TRUE;
}
RETURN_FALSE;
case IS_NULL:
if (zend_hash_exists_ind(array, ZSTR_EMPTY_ALLOC())) {
RETURN_TRUE;
}
RETURN_FALSE;
default:
php_error_docref(NULL, E_WARNING, "The first argument should be either a string or an integer");
RETURN_FALSE;
}
}
In cases where language constructors resemble functions (such as isset, empty, and require), what are the main differences between language constructors and functions?
The "Language builders" as quoted above would be the grammar of the language "consult lexical analyzer". The functions "in this case" would be other functions (functions) defined in modules and extensions of php.
I hope this helps you in some way.