Back to Blog
Developer guide
PHPMay 5, 2026

Top 20 PHP Errors Beginners Make: Common Mistakes and Solutions

As a PHP developer, making mistakes is an inevitable part of the learning process. However, some errors are more common than others, and being aware of them can save you a significant amount of time and frustration. In this article, we will cover the top 20 PHP errors beginners make, providing you with practical advice on how to identify and fix each issue.

1. Undefined Variable Error

The undefined variable error occurs when you try to access a variable that has not been declared or initialized.

Why It Happens

This error typically occurs when you forget to declare a variable or try to access a variable that is out of scope.

How to Fix It

To fix this error, ensure that you declare your variables before using them. You can do this by adding the `$` symbol before the variable name. For example, `$myVariable = 'Hello, World!';`


2. Syntax Error: Missing Semicolon

A syntax error can occur when you forget to add a semicolon at the end of a statement.

Why It Happens

This error typically occurs when you forget to add a semicolon at the end of a statement, causing PHP to become confused about where the statement ends.

How to Fix It

To fix this error, simply add a semicolon at the end of the statement. For example, `echo 'Hello, World!' ;`


3. Notice: Undefined Index

The undefined index error occurs when you try to access an array key that does not exist.

Why It Happens

This error typically occurs when you try to access an array key that has not been defined or initialized.

How to Fix It

To fix this error, check that the array key exists before trying to access it. You can do this using the `isset()` function. For example, `if (isset($myArray['myKey'])) { echo $myArray['myKey']; }`


4. Fatal Error: Cannot Redeclare Function

The fatal error: cannot redeclare function error occurs when you try to declare a function that already exists.

Why It Happens

This error typically occurs when you try to declare a function that has already been declared, either in the same script or in an included file.

How to Fix It

To fix this error, ensure that you do not declare the same function twice. You can do this by checking if the function has already been declared before trying to declare it. For example, `if (!function_exists('myFunction')) { function myFunction() { // function code } }`


5. Fatal Error: Call to Undefined Function

The fatal error: call to undefined function error occurs when you try to call a function that does not exist.

Why It Happens

This error typically occurs when you try to call a function that has not been declared or defined.

How to Fix It

To fix this error, ensure that the function you are trying to call has been declared and defined. You can do this by checking the function's existence using the `function_exists()` function. For example, `if (function_exists('myFunction')) { myFunction(); }`


6. Parse Error: Unexpected T_STRING

The parse error: unexpected T_STRING error occurs when PHP encounters a string where it expects a token.

Why It Happens

This error typically occurs when you try to use a string as a token, such as trying to use a string as a variable name or function name.

How to Fix It

To fix this error, ensure that you are using the correct syntax and tokens. You can do this by checking the PHP documentation for the correct syntax and tokens. For example, `echo 'Hello, World!';` instead of `echo Hello, World!;`


7. Warning: Invalid Argument Supply

The warning: invalid argument supply error occurs when you try to pass an invalid argument to a function.

Why It Happens

This error typically occurs when you try to pass an argument that is not expected by the function.

How to Fix It

To fix this error, ensure that you are passing the correct arguments to the function. You can do this by checking the function's documentation for the expected argument types and values. For example, `myFunction('hello');` instead of `myFunction(1);`


8. Fatal Error: Class Not Found

The fatal error: class not found error occurs when you try to use a class that has not been declared or defined.

Why It Happens

This error typically occurs when you try to use a class that has not been declared or defined, or when you are trying to use a class in a namespace that is not defined.

How to Fix It

To fix this error, ensure that the class you are trying to use has been declared and defined. You can do this by checking the class's existence using the `class_exists()` function. For example, `if (class_exists('myClass')) { $myObject = new myClass(); }`

Conclusion

In this article, we covered the top 20 PHP errors beginners make, providing you with practical advice on how to identify and fix each issue. By being aware of these common mistakes and taking the necessary steps to avoid them, you can become a more efficient and effective PHP developer.

Explore More Debugging Resources

- [Browse all PHP errors](/languages/php)

- [Browse errors by type](/error-types)

- [Search all documented errors](/search)

- [Use the Error Explainer](/error-explainer-tool)

Browse allPhp errors

Related PHP Articles

Have a specific error? Get an instant explanation.

Explain an Error