List of PHP Keywords

••• List of PHP Keywords

As we saw in a simple program of PHP in the previous post First Program in PHP, we use the list of php keywords. there are various words, letters, and digits. Every word used in a PHP program is classified either as a Keyword or an Identifier. So in this tutorial, you will learn about PHP programming Keywords and Identifiers.

These words have special meaning in PHP. Some of them represent things which look like functions, some look like constants, and so on – but they’re not, really: they are language constructs. You cannot use any of the following words as constants, class names, function or method names. Using them as variable names is generally OK, but could lead to confusion.

As of PHP 7.0.0 these list of php keywords are allowed as property, constant, and method names of classes, interfaces and traits, except that class may not be used as the constant name.

List of PHP Keywords

PHP Keywords
__halt_compiler() abstract and array()
break callable case catch
clone const continue declare
die() do echo else
empty() enddeclare endfor endforeach
endswitch endwhile eval exit()
final finally for foreach
global goto if implements
include_once instanceof insteadof interface
list() namespace new or
private protected public require
return static switch throw
try unset() use var
as class default elseif
endif extends function include
isset() print require_once trait
while xor yield

 1 ) __halt_compiler()

This function can be used in eval() — it will halt the eval, but not the script eval”() was called in.

Halts the execution of the compiler. This can be useful to embed data in PHP scripts, like the installation files.

Byte position of the data start can be determined by the __COMPILER_HALT_OFFSET__ constant which is defined only if there is a __halt_compiler() presented in the file.

# Example

void __halt_compiler ( void )

$fp = fopen(__FILE__, 'r');
 // seek file pointer to data fseek
 // and output it
 // the end of the script execution 
the installation data (eg. tar, gz, PHP, etc.)

2 ) abstract

It is not allowed to create an instance of a class that has been defined as abstract.”. It only means you cannot initialize an object from an abstract class. Invoking static method of abstract class is still feasible.

# Example:

abstract class Foo {
 static function bar() { 
echo "test\n";

3 ) and

The constant true is assigned to $h before the “and” operation occurs.

# Example:

// The result of the expression (true && false) is assigned to $g
// Acts like: ($g = (true && false))
$g = true && false;

// The constant true is assigned to $h before the "and" operation occurs
// Acts like: (($h = true) and false)
$h = true and false;

var_dump($g, $h);