Runtime Error
Cannot pass string by reference as a wrapper in /var/www/html/api.php on line 120
What This Error Means
This error occurs when attempting to use a string as a reference type, which is not allowed in PHP. It typically happens when using the 'by reference' keyword (&) with a string variable.
Why It Happens
This error is usually caused by a misunderstanding of PHP's variable types. When using 'by reference', PHP expects a variable that can be modified directly, but strings are immutable and cannot be passed by reference.
How to Fix It
- 1To fix this error, replace the string variable with a variable that can be modified, such as an array or an object. Alternatively, remove the 'by reference' keyword (&) and pass the string as a value instead. For example:
- 2// Before (broken code)
- 3function update_string(&$str) {
- 4 $str = 'new string';
- 5}
- 6uupdate_string('original string');
- 7// After (fixed code)
- 8function update_string($str) {
- 9 return 'new string';
- 10}
- 11uupdate_string('original string');
Example Code Solution
function update_string(&$str) {
$str = 'new string';
}
uupdate_string('original string');function update_string($str) {
return 'new string';
}
uupdate_string('original string');Fix for Cannot pass string by reference as a wrapper in /var/www/html/api.php on line 120
Browse Related Clusters
Related PHP Errors
PDOStatement::execute(): SQLSTATE[HY000] [2002] No such file or direct
Unexpected '}' at end of file in /var/www/html/script.php on line 1
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter
Warning: Cannot redeclare class Foo in /var/www/html/autoloader.php on
Related PHP Blog Articles
Have a different error? Get an instant explanation.
Explain Another Error