Find Available Solution Here!

Reserved Keywords

Deepak Jul 22, 2024

Reserved words are predefined keywords in a computer programming language. These Reserved keywords can be any string of characters that have any meaning or without any meaning.

Example :
Reserved keywords in PHP
  • Isset
  • Print
  • Abstract
  • Function
Click Here to find more reserved keywords on php.net

Reserved keywords in JAVA
  • Package
  • Volatile
  • Transient
  • Synchronized
Click Here to find more java reserved keywords

Reserved keywords in MYSQL
  • AVG
  • BIT
Click Here to find more mysql reserved keywords

These reserved keywords should NOT be used as user-defined names to define an element, variable, or identifier in code.

Reserved keywords require special treatment to use if applicable.

How to create a record if the mysql table column name matches with a reserved keyword?

Let's understand what would be an issue if we use the reserved keyword as a column name.

Created a table with column name as limit (Where the limit is reserved keywords used by MySQL to return records as given Ex. Limit n,m where n&m can be any number)

CREATE TABLE `tbl_employee` (
 `name` varchar(255) NOT NULL,
 `email` varchar(255) NOT NULL,
 `limit` varchar(50) DEFAULT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `name` (`name`)

It will raise an error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit)...... once we try to create a record in following way

INSERT INTO `tbl_employee` (name, email, limit) VALUES ( 'test', 'test@testdemo.com', 4);

To overcome the above syntax error we need to fix it in the following way

  • It is good practice that we Don't use reserved keywords as table names or column names whenever possible.
  • Reserved words must be quoted before being used as a column name or table in MySQL.

Let's quote the column name and rewrite the above insert query again in the following manner

INSERT INTO `tbl_employee` (`name`, `email`, `limit`) VALUES ( 'test', 'test@testdemo.com', 4)

//Output: 1 row inserted.

Note: It is good practice to quote column names during CRUD operation to avoid any such errors.

Can we use reserved words as class name or function name in php?

You can not use reserved keywords as class or function names.

You will receive Response Code: 500 Internal Server Error in most of the cases.

Sometimes it is hard to detect such errors initially until we check the server log to trace such errors.

Such errors can be avoided if we use IDE like Netbeans, PhpStorms, etc. where we get a warning while creating such classes or functions.

Here is some example with error response

Use reserved keywords as class name

class final {
   public function isTest($param) {
    echo "hello final";

Where final is reserved keyword.

It will raise error PHP Parse error: syntax error, unexpected 'final' (T_FINAL), expecting identifier (T_STRING)

Use reserved keywords as function name

 function isset($param) {

     echo "hello isset";

Where isset is reserved keyword.

It will raise error PHP Parse error: syntax error, unexpected 'isset' (T_ISSET), expecting '('

Can Reserved keywords be used as a variable / method name in java?

You should NOT use Reserved keywords to declare variables/method name. It will be BUILD FAILED if used in such a way.

Most IDEs will prompt a warning while we use reserved keywords to declare variables.

The Most common error message will be reported as below once declare the param name or method name using Reserved keywords.

  • not a statement
  • illegal start of type
  • ';' expected

Example :
public class JavaApplication {

    public static void main(String[] args) {

       //Defined integer variable name as a package where the package is a reserved word

        int package =  10;

Above will not build and raise the following errors

JavaApplication.java:13: error: not a statement int package = 10;

JavaApplication.java:13: error: ';' expected int package = 10;
2 errors

Was this post helpful?

Send Feedback

Connect With QuizCure

Follow Us and Stay tuned with upcoming blog posts and updates.

Contributed By



51 Posts
  • PHP
  • JAVA
  • SEO
Scroll up