Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in Laravel project

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Understanding and Resolving "Parse error: syntax error, unexpected 'const'..." Errors in Laravel Projects Introduction The Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) you encounter might be due to a variety of reasons. This blog post aims to explore these reasons and shed light on how to fix them effectively in your Laravel project. Keep reading to gain insights into the root causes and possible solutions for this error. Reason 1: PHP Version Compatibility As illustrated in the given example, the local server's PHP version is 7.2.0 while Bluehost uses PHP 7.0.0. Since PHP 7.0.0 was released back in June 2015 and Laravel was in its early stages at that time; it might have used certain syntaxes or features that are now considered deprecated or not supported on newer versions. The conflict with the syntax (const) could be a result of this version disparity. To resolve this issue, use the latest PHP version on both your local machine and Bluehost. By keeping up-to-date, you can avoid such errors in future updates. You might also need to upgrade your project's Laravel framework version if it is older than 5.4, which introduced const syntax alongside other enhancements. Reason 2: Missing Namespace for Constants The code example shows that the namespace for constants (Doctrine\DBAL) is being directly used within the class without including its proper namespace declaration. This missing namespace might trigger the "unexpected 'const'..." error, as the parser doesn't recognize it. To fix this, ensure you have declared all namespaces for your classes or constants at the beginning of the file, as shown below: