So I'm trying to do something like this:
function func() {
    $call = function() {
        ...
    };
    $call();
}
But it's throwing an error saying:
Function name must be a string
I also tried calling the function like this:
$this->call();
call(); // and like this
And it's not working as well.
Is there a reason why I can't do what I'm doing?
EDIT
It seems to be a problem with the original code, and not in the example I wrote
This is my real code:
$data = [...];
$menu_array = [];
$getChildren = function($id) {
          $children = [];
          foreach ($data as $node) {
              if ($id == $node["parent"]) {
                  array_push($children, $node);
              }
          } 
          return empty($children) ? null : $children;
        };
        $check = function($arr, $dat) {
            foreach ($dat as $node) {
                $children = $getChildren($node["id"]);
                if ($children == null) {
                    $arr[$node["display_name"]] = $node["model"];
                } else {
                    $arr[$node["display_name"]][] = $children;
                    $check($children);
                }
            }
        };
$check($menu_array, $data);
The error is thrown in this line:
$children = $getChildren($node["id"]);
 
    