how to replace string in streamserve
Answers
Explanation:
StreamServe variables are always global, which sometimes invites to not-so-good coding. Let’s say you calculates a $Total in an invoice, and everything works fine. Two years later you add some script in a function where you use the variable $Total, without knowing it’s already used. Even though this function should do something really harmless, you end up having the wrong Invoice total. I will here describe how I try to avoid this and similar problems, when coding StreamServe functions. First of all I use the prefix tmp before all temporary variables in a function, for example $tmpPos. Then I start by setting a value, or clearing the variable, so that I know and control the status of it. If I call another function script from within this function, there is still a risk that the called function might have the same function name, now or in the future. Then I use even more unique variable names, like $tmpMyFunctionTotal, using the name of the current function. I believe that all functions should be written without using external global variables, if possible. All information should therefore come as parameters, and the result should be returned as a return value from the function. Other things I usually do in functions is to write a comment header, explaining what the function does. Thanks Suss and BQ for the enhancements in this sample. I also usually save the return value in a variable, $tmpRet, and use it for logging. I then use the log function at the end of the function, with log level 9, showing the function