Somebody said that when your PHP code and application use global variables then it must be spaghetti code (I assume this). I use WordPress a lot. As far as I know, it's the best thing near great PHP software. And it uses many global variables to interact between its components.
But forget about that, because frankly, that's the only thing I know. So it's completely biased ;D
So, I am just curious, What is the characteristic of spaghetti code?
PS: the only thing I know is WordPress. So, hopefully, maybe this will help somebody give a great answer for somebody who has little experience in developing a full web application on PHP (for example, the Stack Overflow website).
goto
's,In essence, a lack of design and forethought, and just a mishmash of hacks slapped together. This applies to any language, not just PHP.
for somebody who has little experience in developing a full web application on PHP (for example, the Stack Overflow website)
Just FYI, but Stack Overflow was not developed with PHP.
Well, talking of comment you posted, the explanation is very simple.
Using global
operator makes source of a variable is unknown, like other end of spaghetti noodle. It can be defined everywhere. So, when you call your function, you have no idea what value this variable has. Instead of it, direct passing a variable makes it plain and clear:
function hello_testing($conditional_random) {
if ($conditional_random)) {
echo "foo is inside";
}
}
P.S. http://en.wikipedia.org/wiki/Spaghetti_code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With