“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

后端 未结 28 947
盖世英雄少女心
盖世英雄少女心 2021-01-24 14:18

I\'m running a PHP script and continue to receive errors like:

Notice: Undefined variable: my_variable_name in C:\\wamp\\www\\mypath\\index.php on line 10

28条回答
  •  遥遥无期
    2021-01-24 15:01

    Regarding this part of the question:

    Why do they appear all of a sudden? I used to use this script for years and I've never had any problem.

    No definite answers but here are a some possible explanations of why settings can 'suddenly' change:

    1. You have upgraded PHP to a newer version which can have other defaults for error_reporting, display_errors or other relevant settings.

    2. You have removed or introduced some code (possibly in a dependency) that sets relevant settings at runtime using ini_set() or error_reporting() (search for these in the code)

    3. You changed the webserver configuration (assuming apache here): .htaccess files and vhost configurations can also manipulate php settings.

    4. Usually notices don't get displayed / reported (see PHP manual) so it is possible that when setting up the server, the php.ini file could not be loaded for some reason (file permissions??) and you were on the default settings. Later on, the 'bug' has been solved (by accident) and now it CAN load the correct php.ini file with the error_reporting set to show notices.

提交回复
热议问题