php-reports
php-reports copied to clipboard
Error "invalid variable name: { name: " given for all sample reports
Hi I just tried the source and without doing anything when I went for reports, it "
invalid variable name: { name: ""
And i followed the official tutorial and still got errors, so I tried removing parts around and the error went when I changed
VARIABLE : { ..
to
VARIABLE { ....
in the header file. This seems like a bug to me
Thanks
UPDATE
just found out that PHP 7 has removed the support for /e in preg_replace
so starting from PHP7 the custom json_decode breaks, it says to use preg_replace_callback instead
I'll try to put up a fix
FIX
Add this to lib/PhpReports.php under json_decode function It will replace the preg_replace with preg_replace_callback for php7 systems
if(PHP_MAJOR_VERSION >= 7){
//replace single quoted values
$json = preg_replace_callback('/:\s*\'(([^\']|\\\\\')*)\'\s*([},])/', function($m){
return ':'.json_encode(stripslashes($m[1])).$m[3];
}, $json);
//replace single quoted keys
$json = preg_replace_callback('/\'(([^\']|\\\\\')*)\'\s*:/', function($m){
return json_encode(stripslashes($m[1])).':';
}, $json);
}else if(PHP_MAJOR_VERSION < 7){
//replace single quoted values
$json = preg_replace('/:\s*\'(([^\']|\\\\\')*)\'\s*([},])/e', "':'.json_encode(stripslashes('$1')).'$3'", $json);
//replace single quoted keys
$json = preg_replace('/\'(([^\']|\\\\\')*)\'\s*:/e', "json_encode(stripslashes('$1')).':'", $json);
}
This is my json_decode
`public static function json_decode($json, $assoc=false) {
if(PHP_MAJOR_VERSION >= 7){
//replace single quoted values
$json = preg_replace_callback('/:\s*\'(([^\']|\\\\\')*)\'\s*([},])/', function($m){
return ':'.json_encode(stripslashes($m[1])).$m[3];
}, $json);
//replace single quoted keys
$json = preg_replace_callback('/\'(([^\']|\\\\\')*)\'\s*:/', function($m){
return json_encode(stripslashes($m[1])).':';
}, $json);
}else if(PHP_MAJOR_VERSION < 7){
//replace single quoted values
$json = preg_replace('/:\s*\'(([^\']|\\\\\')*)\'\s*([},])/e', "':'.json_encode(stripslashes('$1')).'$3'", $json);
//replace single quoted keys
$json = preg_replace('/\'(([^\']|\\\\\')*)\'\s*:/e', "json_encode(stripslashes('$1')).':'", $json);
}
return json_decode($json, $assoc);
}`
And still getting the errors:
8 reports contain errors ado/names.pivot - Info Header: Unknown parameter '{ created: "2013-08-14" }' view source edit ado/names.ado - Invalid variable name: { name: "range" view source edit mysql/all-orders.sql - Invalid variable name: { name: "range" view source edit mysql/drilldown/customer-orders.sql - Invalid variable name: { name: "id" view source edit php/timezones_multiple.php - Invalid variable name: { name: "regions" view source edit php/functions.php - Options Header: Unknown parameter '{ ignore: true }' view source edit php/timezones.php - Unknown report in INCLUDE header 'php/{report: "functions.php"}' view source edit mongodb/log-events.js - Options Header: Unknown parameter '{ mongodatabase: "Logs" }' view source edit
Any update on this issue? I have the same issue with xenial64
I'm not sure why the above code isnt working, can you post the phpinfo here?
Hy ManZzup, your code solved me the "PHP 7 Warning: preg_replace(): The /e modifier is no longer supported". But still getting "Invalid variable name: { name: " .
Best wishes.
The exception of this error is in the file "php-reports/classes/headers/VariableHeader.php"
Exactly in this code: if(!preg_match('/^[a-zA-Z][a-zA-Z0-9_-]*$/',$params['name'])) throw new Exception("Invalid variable name: $params[name]");
The params['name'] output is the attribute. Example: { name: "regions"
Make sense for someone ?
@elnomade @henrisouzarj I assume you have commented out the rest of the method as @glpunzi has posted.The full method should look like this.
FYI I am also getting the same error 'Invalid variable name: myvariablename'. I have added the fix by @glpunzi but to no success. As hinted by @henrisouzarj, I commented out the line 52 in php-reports/classes/headers/VariableHeader.php: //if(!preg_match('/^[a-zA-Z][a-zA-Z0-9_-]*$/',$params['name'])) throw new Exception("Invalid variable name: $params[name]"); Error is obviously not showing up anymore but one needs to be careful to only use alphanumeric characters in their variable name.