In Drupal, many functions use the following code:
function foo() {
if ($edit = $_POST['edit']) {
// let's do stuff with the post variables
}
}
Using the Drupal way of coding for my own projects, I used the same $edit = $_POST['edit'] line in one of my websites. PHP then returned me "Notice: Undefined index: edit in C:\Program Files\Apache2\htdocs\shop\login.php on line 5" every time when the page was loaded directly from the browser (so: no form data was submitted).
I wondered why I got this notice with my own application, and not when running Drupal. In bootstrap.inc I found Drupal uses it's own error handler, which saves application errors in the watchdog table. Notices are not being saved, though. The watchdog function filters them out.
My question is - strictly taken, foo() should be written something like this:
function foo() {
if (isset($_POST['edit']) {
$edit = $_POST['edit']
// let's rock on...
}
}
Now, although not being stored, the PHP interpreter still notices this error -- which is probably slowing down the application, even if it is just a millisec. Why weren't the core developpers (obviously very experienced programmers) more strict in handling the $_POST variables?
Comments
this is being solved
the forms API will -- eventually, when all forms get converted to form_id_execute -- solve this. Just today I added some anti-notices code to forms API. Stay tuned.
--
Read my developer blog on Drupal4hu.
--
Drupal development: making the world better, one patch at a time. | A bedroom without a teddy is like a face without a smile.