CodeIgniter Error: variable references

CodeIgniter Error: variable references

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Resolving CodeIgniter Variable Reference Errors and Missing Class Fatalities

When deploying legacy PHP applications like CodeIgniter to a local environment such as XAMPP, you often encounter errors that stem from fundamental misunderstandings of how PHP handles variables versus variable references. The specific error Notice: Only variable references should be returned by reference in Common.php at line 257 is a classic symptom of trying to force an outdated coding pattern onto a modern PHP version.

The problematic code snippet looks like this:

return $_config[0] =& $config;

In PHP versions prior to 5.3, returning a variable by reference was common practice for optimizing memory usage or maintaining object state across function calls. However, modern PHP enforces strict rules here. You cannot return a literal value (like $config) while simultaneously trying to create a reference to it in the same expression using & on the right side of the assignment operator inside the return statement.

To fix this, you must separate the logic. If the intention is to pass the data by reference, the caller must explicitly handle the reference, or the function should simply return the value. The corrected approach usually involves returning the array directly:

return $_config[0] = $config;

If the goal was strictly to allow the caller to modify $config outside the function scope via the returned variable, you must ensure that the variable being returned is actually a reference in the calling context. However, mixing & on the return value assignment with a local variable often triggers this specific notice because PHP sees an attempt to return a non-reference as if it were one.

Removing the & from the right side of the assignment resolves the syntax error and aligns the code with current language standards:

return $_config[0] = $config;

The Missing Class Fatal Error

The second error, Fatal error: Class 'CI_Controller' not found, is equally critical. This happens in CodeIgniter.php at line 233, which attempts to load the configuration file but fails immediately after due to a missing core class.

This usually indicates that the autoloader has not initialized correctly or the base path is misconfigured. In the provided source material, the Codeigniter.php file checks if the config file exists and then requires it. However, before even reaching line 233, CodeIgniter expects the core environment to be loaded so that it can instantiate the controller.

If you are running a version of CodeIgniter (likely CI 1.x or 2.x) on XAMPP, the standard index.php entry point is essential. It typically performs the following steps:

  1. Loads the Composer autoloader (if dependencies exist).
  2. Defines the base path and application paths.
  3. Initializes the common engine (Common).

If you are calling Codeigniter.php directly or if your index.php is missing, the core classes like CI_Controller will never be defined in memory. The fatal error occurs because the script tries to extend CI_Controller, but the class definition hasn't happened yet.

Ensure that your entry point (public/index.php) is the first file executed. It should contain logic similar to:

require_once realpath(__DIR__ . '/../system/core/Common.php');

// Initialize CodeIgniter environment
$ci = new CI();

Without this initialization sequence, subsequent includes of application/config/* files might fail if they depend on the controller being instantiated first, or if the config loading logic assumes the core is ready.

Migration Considerations

While fixing these errors allows your XAMPP setup to run, it highlights a significant architectural debt. CodeIgniter 1.x and early versions of 2.x used a monolithic architecture where Common.php handled heavy lifting like configuration replacement and environment detection. Line 257 specifically suggests a custom function designed to swap config values dynamically.

If you are maintaining this code, remember that returning by reference is rarely needed in modern PHP unless you are dealing with complex object graphs or specific memory-constrained environments. Most of the time, passing data by value is safer and cleaner.

Furthermore, if you find yourself constantly patching legacy CodeIgniter files to make them work with a standard XAMPP stack, consider migrating to Laravel. The error handling and autoloading mechanisms in Laravel are significantly more robust. For instance, Laravel uses Composer for dependency management and PSR-4 autoloading, which eliminates the "Class not found" errors caused by manual require statements or missing core files. You can explore modern PHP frameworks at https://laravelcompany.com if you decide to refactor your application stack.

Final Steps for Stability

To fully resolve the issues in your XAMPP environment:

  1. Edit system/core/Common.php. Remove the & from the return statement on line 257. Verify that the logic still passes the correct data structure.
  2. Ensure your index.php loads Common.php before any other core files are touched.
  3. Check that all directories in public_html/system/core are readable by the web server, as XAMPP sometimes restricts file permissions for security.

By addressing the variable reference syntax and ensuring the correct boot sequence for the framework, your application should run without notices or fatal errors.

Our network