I’m writing a web application in PHP, and I’m getting the following warning in Google Chrome only:
Warning: Cannot use a scalar value as an array in
M:\xampp\htdocs\MyProjectTitle\php\classes.php on line 18
Background: Please note that the web app works just fine in all browsers I tested (Firefox, Chrome, IE), but the warning appearing in Chrome is bugging the hell outta me.
Notes: I have tried restarting Chrome and clearing the Chrome cache. I have tried restarting the computer. I have tried searching the source code in FF and IE to see if the warning was just hidden, but to no avail. The warning is only popping up in Google Chrome, and I have no idea why.
UPDATE: Even though Safari also uses WebKit, it does not show the PHP warning. For some reason, Chrome is the only one that has the PHP warning. Weird stuff!
UPDATE: Here’s the first 21 lines of code:
class Presenter {
public function includeFile($filePath) {
if (is_readable($filePath)) {
include $filePath;
} else {
echo '<p><strong>ERROR 404</strong></p>';
echo '<p>The resource you requested could not be located.</p>';
}
}
public function sanitize($string) {
return preg_replace("/\s/","_",$string);
}
public function set($varname,$value) {
$this->$varname = $value;
$_SESSION[$this->name][$varname] = $value;
return $this; // enables chaining!
}
// And there's more code after this, but I have cut it out here.
}
Note: The above code is inside a PHP class.
UPDATE: I know exactly what lines of code are causing the warning in Chrome (although I still have no clue why Chrome is the only browser that shows the warning). Since my webapp works perfectly despite the warning in Chrome, I have used @ to suppress the warnings in Chrome (I’ll fix the warning later).
UPDATE: I know exactly what lines of code are causing the warning in Chrome (although I still have no clue why Chrome is the only browser that shows the warning…If you know, please let me know!). Since my webapp works perfectly despite the warning in Chrome, I have used
@to suppress the warning as a temporary fix until I can fix it for real later.