Available PHPDoc annotations

Here we list PHPDoc annotations that are being parsed by KPHP.

Skip this page at first reading. Look through it later, when you start using KPHP.

@kphp-… tags for functions

This tag is for non-void functions. If an invocation doesn't use the result (not stored to a variable, not passed as argument), you'll get a compilation error.

If a function turns out to be able to throw an exception, you'll get a compilation error.

Checked exceptions: KPHP would ensure that a function actually throws the same list as you expect in PHPdoc.

Marks this function as ‘inline' for gcc, and codegen implementation places it in .h file (not .cpp).
Note. KPHP auto-inlines simple functions, so you typically don't have to use this annotation.

Forces kphp to start compiling this function even if it is not used explicitly. Typically, is required for callbacks passed as strings, as they are resolved much later.

Indicates, that this function never returns (always calls exit()). While building a control flow graph, KPHP treats all code after such functions' invocations as inaccessible, does not warn on missing break, etc.

Tells KPHP that this function is pure: the result is always the same on constant arguments. Therefore, a function can be called in constant arrays for example.

See generic functions.

Marks a function to be sync. If such a function turns out to be resumable, you'll get a compilation error.
See async programming.

Suppress compilation warning of a specified function.

See embedded profiler.

Makes assembler code of this function aggressively inline everything, avoiding callq. Do not use it without examining assembler output!

Available inspections: array-merge-into, array-reserve, constant-execution-in-loop, implicit-array-cast. These annotations are propagated to all reachable functions by the callstack.
See compile-time performance inspections.

See colored functions.

@kphp-… tags for classes

See serialization and msgpack.

See JSON encode and decode.

Fields of an immutable class are deeply constant and can be set only in __construct(). All nested instances must be also immutable.
Such instances can be stored in an instance cache.

Behaves like that color is written above every method of a class.
See colored functions.

@kphp-… tags for fields

Class fields marked @kphp-const can be set only in __construct(). Constantness is not deep: array elements and nested instance properties can still be modified, so constant is the field itself.

@var / @param / @return — KPHP uses them to restrict types

This is fully discussed in PHPDoc is the way you declare types.

KPHPStorm plugin knows about all doc tags, suggests, and validates them.