PHP Manual
/
Basic knowledge

PHP Keywords

10. 04. 2021

Obsah článku

Almost all programming languages consist of `keywords`, which are special expressions of the language that have a special meaning.

An example of a keyword is the word string, if or echo.

It is important to note that keywords (sometimes also commands) are not functions, so echo, for example, is not a function either.

The list of keywords is good to know because they have special meanings in PHP and cannot always be used for everything. For example, the name of a class must not be the same as one of the existing keywords.

Example parse error

When attempting to process a class named String, a Parse error occurs because PHP does not know if it is a class name or a data type:

This is wrong:

class String
{
// ...
}

List of keywords

Updated keyword list for PHP 7.1:

and, or, xor, for, do, while, foreach, as, return, die, exit, if, then, else, elseif, new, delete, try, throw, catch, finally, class, function, string, array, object, resource, var, bool, boolean, int, integer, float, double, real, string, array, global, const, static, public, private, protected, published, extends, switch, true, false, null, void, this, self, struct, char, signed, unsigned, short, long

Jan Barášek   Více o autorovi

Autor článku pracuje jako seniorní vývojář a software architekt v Praze. Navrhuje a spravuje velké webové aplikace, které znáte a používáte. Od roku 2009 nabral bohaté zkušenosti, které tímto webem předává dál.

Rád vám pomůžu:

Související články

1.
13.
Status:
All systems normal.
2024