Hi, I’m new around here. I’ve started to study how to program a few weeks ago. I’ve done little things before by myself. But now I go to school on two days and work in a company the rest of the week.
My problem is I’ve gotten a tool which uses an old php-version and used register-globals at one point. Around 2014 a work-around was implemented and now my task is to substitute this with superglobals. I’ve read the tutorials at w3schools and the chapter in various books and on various pages. But they all go only as far as how to use them in simple statements. At my company no one has time to answer some questions I have.
I have a configuration file in which the work-around for the register-globals is defined. And all over the script I have variables like: $var etc that are used for sql-queries and if-statements and use input mainly from the post-method.
I thought I could now implement the superglobals by defining anew in the configuration-file as for example $var = (int) $_POST[‘var’];
But then I get a whole lot of undefined-index/variable notices.
So I thought I’d use isset() like so:
[php]
if (isset($_POST[‘var’])) {
$var = (int) $_POST[‘var’];
} else {
// I don’t really know what to do best here either
}
[/php]
But do I have to do that for every single one of the variables? Or is there a way to get this checked for every variable that should consist of something out of $_GET or $_POST in a loop for example?