Bằng cách không khai báo một mảng trước khi sử dụng nó thực sự có thể gây ra vấn đề. Một kinh nghiệm tôi vừa tìm thấy, tôi đã gọi tập lệnh thử nghiệm này như sau: indxtest.php? File = 1STLSPGTGUS Điều này hoạt động như mong đợi.
$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);
Bây giờ tôi sẽ chỉ yêu cầu một tệp, từ một tập lệnh khác mà tôi đã mua, ở trên cùng của tôi và chúng ta có thể thấy các giá trị hoàn toàn sai đối với tệp mảng $ trong khi mảng $ đường dẫn là OK: "checkgroup.php" là lỗi.
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);
Khởi tạo mảng trước, sau đó không có vấn đề!
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);
Đó là cách tôi nhận ra tầm quan trọng của việc khởi tạo các biến vì chúng ta không bao giờ biết được vấn đề mà chúng ta có thể gặp phải sau này và chỉ vì muốn tiết kiệm thời gian, chúng ta có thể sẽ lãng phí nhiều hơn vào cuối cùng. Tôi hy vọng điều này sẽ hữu ích cho những người không chuyên như tôi.
$foo = array()
và nó không phải là một chuỗi được chuyển thành một mảng, v.v.).