0

I generated ol or menus list item and testing work very well in localhost but when I upload to hosting I got errors:

Parse error: syntax error, unexpected T_FUNCTION

I double checked in my code and in localhost it still work. Please help what is wrong with my code.

   function generate_li($product, $parent = NULL) {

        $li = "";
        $p1 = array_filter($product, function($a)use($parent) {
            return $a['parent_id'] == $parent;
        });
        foreach ($p1 as $p) {

            $inner_li = "";
            $p2 = array_filter($product, function($a)use($p) {
                return $a['parent_id'] == $p['id'];
            });
            if ($p2) {
                $inner_li = $this->generate_li($product, $p['id']);
            }
            $li .= "<li class='dd-item' data-id='" . $p['id'] . "'><div class='dd-handle'>" . $p['text'] . "</div>" . $inner_li . "";
            $li .= '<div class="m3dd-handle"><a href="' . base_url('menu_add/' . $p['id'] . '/' . $p['id']) . '">Add</a></div>';
            $li .= '<div class="mdd-handle"><a href="' . base_url('menu_edit/' . $p['relative']) . '">';
            $li .= '<span class="mclose glyphicon glyphicon-edit"></span></a></div>';
            $li .= '<div class="m2dd-handle"><a onclick="return confirm(' . "'" . 'Are you sure want to delete this item' . "'" . ')" href="' . base_url('menu_delete/' . $p['id']) . '"><span class="mclose glyphicon glyphicon-remove"></span></a></div>';
            $li .= "</li>";
        }
        $ol = "<ol class='dd-list'>" . $li . "</ol>";
        return $ol;
    }
chris85
  • 23,846
  • 7
  • 34
  • 51
DMS-KH
  • 2,669
  • 8
  • 43
  • 73

1 Answers1

2

Your host is probably running an older version of PHP (less than version 5.3) which doesn't support closures or anonymous functions. Do a php -v from the command line or use echo PHP_VERSION to confirm the version of PHP running on your webhost.

Since PHP 5.6 is the latest supported of PHP i strongly recommend finding a new host as the version of PHP they are running is obsolete and no longer receiving security patches leaving it vulnerable to attack.

John Conde
  • 217,595
  • 99
  • 455
  • 496
  • *older version* Can't we just call it dead? http://php.net/supported-versions.php It's not even supported anymore. + `phpversion()` might be easier than `phpinfo()` to get what OP needs to check :] – Rizier123 Sep 01 '15 at 18:03
  • 1
    I totally forgot about that function and it's matching constant. Shows you how often I use it. :) – John Conde Sep 01 '15 at 18:04
  • Yes this function I got from Stackoverflow member that help to solved my problem now I still used it – DMS-KH Sep 01 '15 at 18:09