PHP Keywords
PHP's reserved keywords. None of them can be used as a function or class name; $keyword as a variable still works because variables have $ prefix.
Declarations
class interface trait enum function fn const extends implements use namespace declare
Visibility / OOP modifiers
public protected private static final abstract readonly new clone instanceof
Control flow
if elseif else endif
switch case default break continue
match
for endfor foreach endforeach as
while endwhile do
return yield yield from
Exceptions
try catch finally throw
Boolean & null
true false null — case-insensitive but conventionally lowercase.
Logical operators (word form)
and or xor — lower precedence than && / ||; use parens to be safe.
Casts
(int) (float) (string) (bool) (array) (object)
Type names that double as keywords
int float string bool array object iterable callable mixed void never self static parent
I/O
echo print require require_once include include_once
Globals
global list isset empty unset die exit array
List or Match looks ambiguous, prefix it with the namespace: \App\List. PHP 8 quietly let some reserved words become valid class names; not all editors caught up.Example
<?php // Common keywords: // if elseif else endif switch case default match // for foreach while do return break continue // function fn class interface trait extends implements // public private protected static const final abstract // new clone try catch finally throw use namespace echo 'all reserved words are documented at php.net';Try it Yourself »
Exercise
Keyword to declare a function.
Eight letters.
Discussion
Loading…