Unexpected T_FUNCTION

I have release my first plugin (mz mindbody api - which relies on SOAP and PEAR), and a user in Germany is getting syntax error unexpected T_FUNCTION when they try to install it on a clean install using a theme that I can run the plugin on (twentyfourteen).

The error line apparently references the usort in the following code:

function sortClassesByDate($mz_classes = array()) {
    $mz_classesByDate = array();
    foreach($mz_classes as $class)
    {
        $classDate = date("Y-m-d", strtotime($class['StartDateTime']));
        if(!empty($mz_classesByDate[$classDate])) {
            $mz_classesByDate[$classDate] = array_merge($mz_classesByDate[$classDate], array($class));
        } else {
            $mz_classesByDate[$classDate] = array($class);
        }
    }
    ksort($mz_classesByDate);
    foreach($mz_classesByDate as $classDate = $mz_classes)
    {
        usort($mz_classes, function($a, $b) {
            if(strtotime($a['StartDateTime']) == strtotime($b['StartDateTime'])) {
                return 0;
            }
            return $a['StartDateTime']  $b['StartDateTime'] ? -1 : 1;
        });
    }
    return $mz_classesByDate;
}

Does anyone see anything I might be missing?

Topic soap plugin-development Wordpress

Category Web


Check that the user has php >= 5.3 installed. The inline function syntax used on that line only works with that or higher. You can rewrite the line to create a separate function and then call it like this:

usort($mz_classes, 'myFunction');

For more info:

http://php.net/manual/en/function.usort.php

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.