-2

I have a bit of PHP code that works fine on my production server but not on my test server. Here is the code:

function callProcedure0(&$connection, $procname, $dofunction)
{
    mysqli_multi_query($connection, "CALL " . $procname . "();");
    $first_result = 1;
    do
    {
        $query_result = mysqli_store_result($connection);
        if ($first_result)
        {
            $dofunction($query_result);
            $first_result = 0;
        }
        if ($query_result)
        {
            mysqli_free_result($query_result);
        }
        $query_result = NULL;
    } while(mysqli_next_result($connection));
}

...

function doGenres($in_result)
{
    global $genre_array, $game_array, $genre_order_array;
    $genre_count = 1;
    // foreach is necessary when retrieving values since gaps may appear in the primary key
    while ($genre_row = mysqli_fetch_row($in_result))           // line 81 is here!
    {
        $genre_array[] = $genre_row[0];
        $genre_order_array[$genre_row[1] - 1] = $genre_count;
        $game_array[] = [[],[]];
        $genre_count += 1;
    }
}

...

callProcedure0($con, "get_genres_front", doGenres);         // line 138 is here!

The "get_genres_front" bit refers to a stored procedure on my database. Here are the errors:

Notice: Use of undefined constant doGenres - assumed 'doGenres' in /opt/lampp/htdocs/keyboard/keyboard.php on line 138

Again, there are no problems on the production server which is using Apache 2.2.23, MySQL 5.1.73-cll, PHP 5.4.26. The test server where things are broken is running Apache 2.4.10, MySQL 5.6.21, PHP 5.5.19.

Did something change in recent software versions? Thanks.

[edit]

This is not a duplicate question. I'm worried about the first error. I already know what to do about the second error which I have deleted.

posfan12
  • 2,541
  • 8
  • 35
  • 57

1 Answers1

2

The code you have posted is wrong, you must pass function name as string and then use call_user_func to invoke this function.

In your callProcedure0 function change

$dofunction($query_result);

to

call_user_func($dofunction, $query_result);

And then call it with the function name as string like this

callProcedure0($con, "get_genres_front", "doGenres");

The above code could work also with invoking the function with

$dofunction($query_result);

on some php versions, but the line where you pass the function name it should be string, otherwise PHP assumes it is a constant.

Sh1d0w
  • 9,340
  • 3
  • 24
  • 35