iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

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

Tip: If a class name like 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

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.

greet() {}

Test yourself

Q1. PHP reserved words include…
Q2. true/false/null are…
Q3. A "soft keyword" like match…

Discussion

Loading…