Uninitialized variables in PHP

Uninitialized variables in PHP

<?php

if($user==’testuser’) {

$ok = true;

}

if($ok) {

echo “$user logged in”;

}

?>

We can catch these by setting the error_reporting level to E_ALL. The above script would generate this

warning (assuming $user is set):

<b>Warning</b>: Undefined variable: ok in <b>script.php</b> on line <b>6</b>

We can of course also turn off register_globals, but that addresses the symptom rather than the problem.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.