Nie zadeklarowanie tablicy przed jej użyciem może naprawdę spowodować problemy. Jedno doświadczenie, które właśnie znalazłem, nazwałem ten skrypt testowy w ten sposób: indextest.php? File = 1STLSPGTGUS Działa to zgodnie z oczekiwaniami.
$path['templates'] = './mytemplates/';
$file['template'] = 'myindex.tpl.php';
$file['otherthing'] = 'otherthing';
$file['iamempty'] = '';
print ("path['templates'] = " . $path['templates'] . "<br>");
print ("file['template'] = " . $file['template'] . "<br>");
print ("file['otherthing'] = " . $file['otherthing'] . "<br>");
print ("file['iamempty'] = " . $file['iamempty'] . "<br>");
print ("file['file'] = " . $file['file'] . "<br>");
print ("file = " . $file);
Teraz będę potrzebował tylko pliku z innego kupionego przeze mnie skryptu, na górze mojego i możemy zobaczyć, jak wartości są całkowicie błędne dla tablicy $ file, podczas gdy tablica $ ścieżka jest OK: "checkgroup.php" jest winny.
require_once($_SERVER['DOCUMENT_ROOT']."/IniConfig.php");
$access = "PUBLIC";
require_once(CONFPATH . "include_secure/checkgroup.php");
$path['templates'] = './mytemplates/';
$file['template'] = 'myindex.tpl.php';
$file['otherthing'] = 'otherthing.php';
$file['iamempty'] = '';
print ("path['templates'] = " . $path['templates'] . "<br>");
print ("file['template'] = " . $file['template'] . "<br>");
print ("file['otherthing'] = " . $file['otherthing'] . "<br>");
print ("file['iamempty'] = " . $file['iamempty'] . "<br>");
print ("file['file'] = " . $file['file'] . "<br>");
print ("file = " . $file);
Inicjalizacja macierzy wcześniej, to żaden problem!
require_once($_SERVER['DOCUMENT_ROOT']."/IniConfig.php");
$access = "PUBLIC";
require_once(CONFPATH . "include_secure/checkgroup.php");
$path = array();
$file = array();
$path['templates'] = './mytemplates/';
$file['template'] = 'myindex.tpl.php';
$file['otherthing'] = 'otherthing.php';
$file['iamempty'] = '';
print ("path['templates'] = " . $path['templates'] . "<br>");
print ("file['template'] = " . $file['template'] . "<br>");
print ("file['otherthing'] = " . $file['otherthing'] . "<br>");
print ("file['iamempty'] = " . $file['iamempty'] . "<br>");
print ("file['file'] = " . $file['file'] . "<br>");
print ("file = " . $file);
W ten sposób zdałem sobie sprawę, jak ważne jest zainicjowanie zmiennych, ponieważ nigdy nie wiemy, z jakim problemem możemy się później spotkać, a po prostu chcąc zaoszczędzić czas, możemy ostatecznie stracić jeszcze więcej. Mam nadzieję, że będzie to pomocne dla osób takich jak ja, które nie są profesjonalistami.
$foo = array()i że nie był to ciąg zamieniony na tablicę itp.).