I am trying to declare a variable outside a public class in PHP, but for some reason, it does not work.
Here is my code
JavaScript
x
$catID = '33234532';
public static function saveFile($name, $catID){
$name = 'catid_' . $catID . time() . '_' . '.' . pathinfo(saveFiles:sanitizeFileName($name), PATHINFO_EXTENSION);
rest of my code
}
now, when I save the file I get catid__1487393557.png, it completely ignores the $catID.
Now, when I do this below it outputs the right thing.
JavaScript
public static function saveFile($name, $catID){
$catID = '33234532';
$name = 'catid_' . $catID . time() . '_' . '.' . pathinfo(saveFiles:sanitizeFileName($name), PATHINFO_EXTENSION);
rest of my code
}
This outputs this: catid_33234532_1487393557.png
Advertisement
Answer
You can try global variable to declare variable outside function