Search code examples
phpvariablesundefinedversions

extract($_GET) PHP ends up with undefined variable


I am having trouble with:

Notice: Undefined variable: detail in /var/www/html/premysl/php/web_f7mysql.php on line 43

The mentioned line contains some condition with $detail == NULL, which (variable $detail) should be extracted via extract($_GET) written in different file.

Here's the thing - whole project is hosted in root of server with PHP 5.4.13 and works perfectly. Anyway, it doesn't run on a different server with PHP 5.3.3 (cli).

Unfortunately it is necessary to make it work on the second one. I guess there's some "compatibility" issue, maybe different settings.

Do you have any sugestions what to focus on?


Solution

  • Your line that reads like this:

    $detail == NULL
    

    Should be changed to combine isset and !empty like this:

    isset($detail) && !empty($detail)
    

    Also using extract($_GET) is a bit ridiculous. Instead just do this:

    $detail = (isset($_GET['detail']) && !empty($_GET['detail'])) ? $_GET['detail'] : null;
    

    Also as far as the actual error goes:

    Notice: Undefined variable: detail in /var/www/html/premysl/php/web_f7mysql.php on line 43

    Then just stick this line within whatever function is causing this issue in web_f7mysql.php:

    global $detail;