passing in arrays to your functions rather than using variables
this is probably an old technique, but i discovered it the other day when i was playing around, and i thought wow i should do this to all my functions, i cant see the downside, apart from having to remember the array types that are needed, plus you could add defaults if needed anyway to remember them down the track.
Anyway here is my example function before adding the array.
PHP
$list_all_result = $myclass->list_all(
$start = 0,
$max = 50,
$list_type = "latest",
$template_file = "list-item.html",
$search_term = ""
);
the array is now layed out like the following
PHP
$list_options = [
"start" => 0,
"max" => 50,
"list_type" => "latest",
"template_file" => "list.html",
"search_term" => "",
];
and you just pass the array into the function
So rather than calling the funciton with all the variables in it you can just change the parts of the array 1st and then call the function.
PHP
$list_options["list_type"] = "latest";
then run the list_all function with the options
PHP
$imports_list_all = $imports->list();
to get the values in the function just loop through the array and assign all to variables
PHP
foreach ($this->list_options_array as $options_name => $options_value) {
/* ${$options_name} = $options_value; */
${$options_name} = $this->db->escapeString($options_value); // escape all incoming data
$bugs .= "$$options_name: $options_value<br />";
}
makes your code a bit more complex, but i think its valuable