From what I understand, extract()
takes in an array as an argument and creates variables whose names are exactly identical to the keys in this array and whose values are the values associated with these keys respectively.
For example, passing in ['message' => 'this is a message!']
, creates a variable named $message
with the value 'this is a message!'
.
I'm not gonna ask how it converts keys to variable names, but as far as I know, variables in PHP are local if they're declared inside a function.
I just wanna make sure, does extract()
declare these variables as global variables? (because I can't think of a reason why they're still in scope after this function returns except that it declares them as global variables). Is that even possible in PHP?
Also, is it a good practice to use a function like this? I mean, if we already have these values stored in an array, why bother extracting them in new separate variables? If the answer to this question is because, in apology.php for example, we hard-coded the variable name $message
, well, we could simply hard-code $values['message']
. So what's the deal here?