**Creating function inside if statement is not a best practice ** because that will be called if condition is true else will give undefined error in case you call that function later on. Also you called your function before it is even created thats why giving undefined error.
So better to create function outside if statement and run it anywhere.
//Creating function first and then calling it afterwards
function DoConfig($param_data)
{
echo $param_data;
}
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset($_POST['data_id']) && $_POST['data_id'] != NULL){
$data = $_POST['data_id'];
//Function call
DoConfig($data);
}
}else
{
echo '0';
}
EDITED as per your answer: There is absolutely no problem with security if you create it outside if statement, use functions when needed.
Alternatively for future purpose if you are creating function inside if statement then use
function_exist method later on so that you don't get undefined error
https://www.php.net/function_exists