Wenn Sie ein Array vor der Verwendung nicht deklarieren, kann dies zu Problemen führen. Eine Erfahrung, die ich gerade gefunden habe, ich habe dieses Testskript wie folgt aufgerufen: indextest.php? File = 1STLSPGTGUS Dies funktioniert wie erwartet.
$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);
Jetzt benötige ich nur noch eine Datei aus einem anderen Skript, das ich oben gekauft habe, und wir können sehen, wie die Werte für die Array $ -Datei völlig falsch sind, während der Array $ -Pfad in Ordnung ist: "checkgroup.php" ist der Schuldige.
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);
Das Array vorher initialisieren, dann kein 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);
Auf diese Weise wurde mir klar, wie wichtig es ist, Variablen zu initialisieren, da wir nie wissen, mit welchem Problem wir später enden könnten, und nur um Zeit zu sparen, verschwenden wir am Ende möglicherweise noch mehr. Ich hoffe, dass dies für diejenigen wie mich hilfreich ist, die nicht professionell sind.
$foo = array()dass es sich nicht um eine Zeichenfolge handelt, die in ein Array usw. umgewandelt wurde).