Expand Rows Unexpected T_Function Error
Expand Rows Unexpected T_Function Error
Hi,
I am currently working on a database that employs the expand rows feature and I cannot get it to work due to the use of an anonymous function in the .php file provided in the example. I cannot execute this anonymous function since I'm using PHP version 5.2 and anonymous functions were not implemented until version 5.3. When I comment out the anonymous function, the script produces a clean JSON file so it seems like this is the culprit. The anonymous function is called 'formatter'. Is there any way to convert this function into something that can be executed in 5.2, or do I need to upgrade? Here is the code fragment that is causing problems:
// Array of database columns which should be read and sent back to DataTables.
// The db
parameter represents the column name in the database, while the dt
// parameter represents the DataTables column identifier - in this case object
// parameter names
$columns = array(
array(
'db' => 'id',
'dt' => 'DT_RowId',
'formatter' => function( $d, $row ) {
// Technically a DOM id cannot start with an integer, so we prefix
// a string. This can also be useful if you have multiple tables
// to ensure that the id is unique with a different prefix
return 'row_'.$d;
}
),
Answers
Same problem here!
Parse error: syntax error, unexpected T_FUNCTION in ids-arrays.php on line 24
Any ideas how to bypass it?
Sounds very much like you are using a very old version of PHP 5.2 or before as Yamil was. The Editor PHP libraries require PHP 5.3 or newer as the use a number of the newer features to present a nicer API that would be possible in 5.2.
Allan
Yes, I know I can't use that way, since I'm using a old PHP version (5.2). However I was expecting someone has some kind of solution to "convert" that anonymous function to a "normal" function.
We could work around that single function, however the libraries fundamentally require 5.3 since they use namespaces and closures internally. So it isn't just a case of altering that one function.
I do have PHP 5.2 compatible libraries I can e-mail through to you if you want, but they are missing a lot of the features of the newer libraries and are no longer supported.
Allan