- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
FRIST maybe?
TRWTF is Enterprisey PHP
Admin
not frist because aksimet needs shooting...
Admin
This is why people don't like PHP; they see code like this.
As a PHP supporter, I have to point out that PHP DOES allow OOP including some great frameworks.
Just preempting the PHP bashing.
captcha: damnum: my thoughts on this code
Admin
Agreed Fyrilin - PHP isn't as bad as that when it's used with an ounce of common sense.
Given the option if presented with code like this to maintain, it's either being rewritten from the ground up or I'll be making sure the door doesn't hit me too hard on the way out.
Admin
I don't do PHP, but rather C++ so I may be a little off here, but this is a prime reason why you don't use Global variables for anything (Variables that get allocated globally are a different matter - and yes, there is a difference).
Admin
Real PHP WTF
In no specific order
Admin
Yeah, general "rule of thumb", if you cannot count your globals on your fingers, there's probably something wrong. On that note, I once had a vendor BRAG to me that the next release of their software used over 6,000 global variables. The poor fool thought that it was a measure of the size, and therefore sophistication, of their product. To me, well, let's just say that data point explained a lot ;-)
Admin
Variables that get allocated globally are a different matter - and yes, there is a difference."
Are you speaking of heap variables? If so, it's far better to call them "heap variables" than "variables that get allocated globally." If you mean something else, please do educate us.
Admin
A global variable refers to a static, a singleton, a variable where every function/class refers to the same value.
This is contrasted to a member variable, a local variable or a function argument.
This definition, by convention, tends to exclude global constant primitives.
An excess number of global variables is typically a sign something could be redesigned.
Admin
I may be confused here. You have a global db connection that everything seems to be using. In several places it is switched to a testdb and then back. Is this for testing the code against a test environment vs a production environment (which the global variable should be changed to point to the test db) or is there some other reason for this?
Admin
TRWTF is that "fred" is used in the comment block, but not used as a temporary variable name.
(one of my CS professors was in the habit of using "fred" as a temp/nonsense variable name in the same manner as "foo" is often used)
Admin
Admin
All global variables live in the heap, but not all heap variables are global.
Global variables do not live in the heap. A compiler places them into a static section that is loaded straight into memory at load time. No malloc, no free, no heap.
I was asking about what was meant by "variables that are allocated globally" but which are not global variables. I suspected, perhaps incorrectly, that this was a reference to heap variables, which can be made globally accessible (as opposed to stack and member variables, which can only be used in context).
Admin
Admin
"What I did was to swap out the link identifier" so the real WTF is his/her solution to the problem imho.
what would hinder him/her to create another global var for db2?
Admin
Globals can be declared INSIDE FUNCTIONS???
Admin
depends on the language. what you said is true for C and C++ but I suspect is not true for PHP, python, etc
Admin
This is implementation dependent. "Global variable" is a description of semantic scope, not of generated code.
Admin
$GLOBALS['db2'] = ...; and its done -.-
Admin
If you want to access a global variable from inside a function in PHP, you first have to run the statement
. If not, is treated as a local variable.There is also a supoerglobal array called $GLOBALS that would let you access it as $GLOABLS['variableName'].
Good stuff, huh?
Admin
No, that is a comment signed by someone named fred, who apparently worked on the code. It's not the name of a variable.
Ob captcha: WTF is a laoreet? Can I buy one at a petstore? Or is something I shouldn't mention in polite company?
Admin
Global variable increase window of vulnerability. This is well known fact. They are necesary evil in our trade.
Admin
Is it just me that is shaken by the database calls directly in the page? Separation of concerns anyone?
Someone in this thread mentioned something about PHP supporting OO concepts and all these are bad examples of PHP, and that PHP really is good, really honestly... Please, show an example of what "good" PHP would look like...
Also, PHP is TRWTF, amirite?
</obligatory PHP bashing>
Admin
In server-side applications I generally reckon I can count the global variables on the fingers of one foot.
Admin
Admin
What madness is this?! How can someone design an enterprise-y system with a whole mess of globals?!
This reeks like a simple application became a general application became a cross-functional business corporate scorecard analytical engine...
Admin
TRWTF is how many idiots think that they are clever or sophisticated because they bash PHP.
Admin
You could have a look at the symfony framework code, most of it is quite clean and dandy.
Admin
I could not have said it better myself. When the job needs done, a can-do programmer understands that sometimes everything can't be pretty and perfect, and must resort to these necessary evils.
Admin
Errhh FILE, anyone?
Admin
Without discussing the pitfalls of globals, doesn't this have a direct refactoring pattern? replace the code of the function which uses globals with a function call to a new function passing in the globals as parameters. Implement the new function using the original code, replacing the global references with the parameters.
This would work for all old invocations and the new code could just call the new function.
Metro.
Admin
And where is budget for code come from? Remember everything need money.
Admin
Search results in the screenshot seem to talk about instances of '$sql' ?
Admin
Admin
Admin
Not a single comment has pointed out that Amber is female????
Admin
Ambar mean sky in Sanskrit. It is boy's name.
Admin
Not to best of my knowledge and my knowledge is best as far as I know.
Admin
I once read an article that stated that some companies make a mistake of "redesigning something from scratch" when the should have just fixed what was broken, and that there is rarely a reason to redesign from scratch.
This I believe falls into the "redesign from scratch" catagory.
Admin
Surely, you live in fantasy world.
Admin
TRWTF is not PHP, TRWTF how we allow armies of incompetent grunts to work as programmer.
Im pretty sure one can create an enterprisey Fecosystem in any langage.
Admin
Oh, so you're not actually declaring new ones, you're just importing existing ones... that makes sense... sort of...
Admin
I often think that I'm choosing between two evils. Sometimes one is an orthodox evil, global's, goto's, functions with side effects, all these are evil, but sometimes to avoid them brings on worse evils.
Admin
In the UK (England in particular), "Fred" is used as a generic joke name. From what I understand from the lyric sheets of a certain Jefferson Airplane album, the same applies to a greater or lesser extent in the US too, yeah?
Admin
I take it you're a code monkey?
Admin
Someone could do significantly better than the above without using OOP. Bad programmers are bad whether its procedural programming or object oriented programming.
Admin
Make sense. Javascript opts for var to declare a variable locally. PHP opts for global to import from the global scope. They are opposites...
Admin
"Amber" means fossilized tree resin in English, and it is a girl's name. But why should someone want to point that out?
Admin
...and the bugs that stem from such ridiculous code cost money too.... it's a pretty easy argument to forge IMHO. You could also implement changes bit by bit, that is the true way of getting old code improved, don't try to justify doing it in one big hit... most of that can be done "out of scope" with other development too
Admin
Seems many languages permit global variables and few languages prevent global variables. Is that because we are using really old languages from before anybody knew how to structure code? Or are new languages still designed with support for global variables?