Strict Standards: Only variables should be assigned by reference
Upgrading your PHP environment often reveals hidden incompatibilities in legacy codebases. Moving from an older version like XAMPP 1.7.3 to 1.8.0 triggers a specific Strict Standards warning when attempting to assign a function's return value directly by reference using the & operator. This error specifically targets lines where syntax has changed between PHP versions, most notably in how ADODB connections are instantiated.
The problematic code snippet looks like this:
$conn = &ADONewConnection($config['db_type']);
In strict mode, PHP enforces a rule that you cannot assign the return value of a function to a variable by reference unless that function is explicitly declared to return a reference using the & keyword in its definition. In older PHP versions or loose configurations, PHP would silently ignore the ampersand or treat it as an implicit global reference, but modern interpreters throw a Strict Standards: Only variables should be assigned by reference error when they encounter this syntax.
To resolve this without disabling strict reporting, you must refactor how the connection object is initialized. The most direct fix involves removing the leading ampersand from the assignment operator and relying on the internal behavior of the ADODB library to manage the reference correctly upon instantiation.
$conn = ADONewConnection($config['db_type']);
This change aligns with modern PHP best practices where objects are instantiated normally, and reference semantics are handled internally by the class logic. If ADONewConnection returns an object that is intended to be used as a global singleton or passed around heavily by reference within the ADODB framework itself, removing the explicit assignment reference usually does not break functionality because the underlying object state remains accessible.
However, if your application relies on passing $conn by reference to other functions immediately after creation, you must ensure those specific function signatures accept references. For example, a legacy method might be defined as function doSomething(&$db). In such cases, calling ADONewConnection() without the ampersand and then passing it to doSomething($conn) will work perfectly fine because PHP allows passing non-reference variables to reference parameters; the variable itself is not copied by value in a way that breaks isolation here.
If removing the & causes issues with your specific ADODB version or custom wrappers, you have an alternative approach: redefine the connection as a static global property at the top of the file and assign it without the reference operator during initialization. This pattern separates the creation logic from the assignment scope, avoiding the parser error entirely while maintaining global accessibility.
// Define globally if needed for legacy ADODB usage
global $conn;
$conn = ADONewConnection($config['db_type']);
By adhering to these structural changes, you maintain strict compliance with PHP 5.4+ standards without needing to mask errors via error_reporting configuration. This ensures that your application remains robust across different hosting environments where E_STRICT might be enabled by default.
For developers working within the Laravel ecosystem or other modern frameworks, this specific legacy pattern is rarely encountered due to strict dependency management and object-oriented conventions enforced by libraries like PDO and Eloquent. If you find yourself maintaining a mixed-codebase where ADODB persists alongside newer standards, isolating these legacy initialization blocks into their own helper files can prevent future Strict Standards warnings from bubbling up unexpectedly.
Ultimately, the fix is straightforward: stop forcing reference assignment on function return values unless the function signature explicitly mandates it. Let the PHP engine handle object references naturally to ensure long-term compatibility and cleaner error logs.
