The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Or a bit more pronounced - A global is accessible from anywhere in the entire program. Each time you introduce a global, you thus potentially affect any part of your application. This means that with a complex application, the consequences are incomprehensible.
Possibly worse though, is that whenever someone (for example a thirdparty developer) needs to write any piece of code which interacts with you application (or indeed just run alongside it), the programmer will need to take each and every global into consideration.

This reminds me of a contract I had to work on, fixing someone else code. Instead of using regular function parameters, the previous programmer would pass data into functions by writing values into the $_POST array. As you can imagine, this was a nightmare to debug.

Thing is, as far as clean OOP code people go, higher quality = more sophisticated code. For us sophisticated code might seem like a good, easy to modify and build upon solution, but for most people, most users, and even most contributors, it's "class... method.. what??"

Pretty much everyone I know of who uses forums such as phpBB, or hell, even vBulletin, does so because of the literally hundreds upon hundreds of modifications that are freely available that literally allow you to make a board the way you want it to. Who's making these modifications? How much support would an app that requires someone to learn proper programming to modify get instead of one which can be used to start learning programming?

What does proper programming mean? You can easily satisfy the half-arsed programmer crowd, you just have to build something simple. But if you're bulding something for the hardcore programmers, the result will be that half of them won't care, and the other half will disagree with your methods for the most obscure of reasons.

Unless your going to go commercial with your code I see no reason as to why you can't code how you want, uncommented, sloppy, badly formatted, whatever. It usually won't be a problem if its only you looking at it. I can write a several thousand line piece of software without any documentation and still understand the whole thing (since it was a result of my thinking).

Now if your going commercial, I can see why you may want to use better coding habbits.

Quality is sophistication. I think you should perhaps say "not to confuse quality with success or popularity". Because the most successful or the most popular is rarely the best quality.

Originally Posted by Edman

Thing is, as far as clean OOP code people go, higher quality = more sophisticated code. For us sophisticated code might seem like a good, easy to modify and build upon solution, but for most people, most users, and even most contributors, it's "class... method.. what??"

Most contributors, and I dare say, most developers of these projects never did Computer Science so they don't really understand any of these concepts. They may talk about them but they don't know how important or useful those are. If a quick Google search for tutorials returns some code that they can hack into the scripts which make them work after a page refresh, then that's good enough.

Be careful before you jump to conclusions about open source PHP code though. I've seen commercial code that is just as bad if not worse. The difference is that they aren't open so most people don't get the chance to see and criticize them.

"I disapprove of what I say,
but I will defend to the death my right to say it."

What does proper programming mean? You can easily satisfy the half-arsed programmer crowd, you just have to build something simple. But if you're bulding something for the hardcore programmers, the result will be that half of them won't care, and the other half will disagree with your methods for the most obscure of reasons.

Funny, but so true!

There seems to be an endless amount of opinions on the proper MVC-implementation, for example.

So... do good (as defined in this context) PHP programmers just suck at creating Opensource projects? Or do they suck at making them popular? Do they lack all the other skills necessary to keep a project alive and grow it? Or is it that they rather work on paying projects (don't think that is it, because the PHP-based products that were being sold, that I've seen were even worse than their opensource counterparts)? Maybe they prefer to consult and do individual work, which hapens to shield them from public evaluation...?

There aren't many places to find good advice if you're trying to learn.

I would say that there are arguably more PHP resources out there than for any other scripting language.

That's true. But the majority of those resources - well, suck. I myself have only relatively recently found these great sites that have good advice dealing with high-class concepts, and I have been doing PHP for quite a long time.

Or, in other words, the majority of PHP resources are exactly the same quality as the majority of PHP forum software.

PHP is consistently seen as an "amateur" language because primarily amateurs use it and hence produce exceedingly amateur code. This in turn means that the majority of times when a person sees PHP code it's a pile of festering, malignant ooze spawning global variables and heredoc syntax.

The good news is that those amateurs who really are interested will quickly become good programmers due to actively improving their skills.

Originally Posted by R. U. Serious

So... do good (as defined in this context) PHP programmers just suck at creating Opensource projects? Or do they suck at making them popular? Do they lack all the other skills necessary to keep a project alive and grow it?

That's not a failing of PHP programmers, per se, it's a downside of Free/Open Source in general. It's really, really hard to stay motivated on something you're not getting any tangible reward for (read: money), and that doesn't change if you're programming in PHP, .NET, Ruby, or $LANGUAGE. Even if you really believe in what you're creating eventually your enthusiasm will fade.

This reminds me of a contract I had to work on, fixing someone else code. Instead of using regular function parameters, the previous programmer would pass data into functions by writing values into the $_POST array. As you can imagine, this was a nightmare to debug.

nasty.

Originally Posted by BerislavLopac

Oh my. Even globals are better than this...

You mean, using $GLOBALS is better (I agree), but $_GET, $_POST etc. are globals aswell, and thus they are in the red zone as far as I'm concerned.
There are two justifications for superglobals in PHP - one being that they are (or were meant to at least) read-only. You generally won't write to $_POST or $_GET, which of course makes so much worse when somebody actually does it. And second, it's a language-feature.
Still - I don't ever write code which access said superglobals directly at the application-level. Instead I wrap it in a request-object. Most serious PHP projects does something similar.

I hate to make a shameless plug, but feel free to check out http://k4bb.org. It is my brother's software. I'll say right away that there is a lot of room for improvement, but there are also some good things in there.

You mean, using $GLOBALS is better (I agree), but $_GET, $_POST etc. are globals aswell, and thus they are in the red zone as far as I'm concerned.
There are two justifications for superglobals in PHP - one being that they are (or were meant to at least) read-only. You generally won't write to $_POST or $_GET, which of course makes so much worse when somebody actually does it. And second, it's a language-feature.
Still - I don't ever write code which access said superglobals directly at the application-level. Instead I wrap it in a request-object. Most serious PHP projects does something similar.

Agree. Globals are a real problem as it counters the benefits of what polymorphism is all about.

So... do good (as defined in this context) PHP programmers just suck at creating Opensource projects? Or do they suck at making them popular? Do they lack all the other skills necessary to keep a project alive and grow it? Or is it that they rather work on paying projects (don't think that is it, because the PHP-based products that were being sold, that I've seen were even worse than their opensource counterparts)? Maybe they prefer to consult and do individual work, which hapens to shield them from public evaluation...?

What do you think?

First of all, I find most programmers who are very good often have their head up their own ****. That's true, btw, for pretty much every single part of an industry where excellence is achieved. Industries where logical thinking isn't required are far worse off. This leads to very opinionated people, which in turn leads to products that are considered to be extremely good by some very good programmers to be considered extremely bad by others due to 5 lines of code that could have been written differently.

Secondly, many many of the very very good programmers stop being programmers. Instead they are hired by large companies to lead teams. Or they find a way to start their own business. If you're a freelancer, you need 2 years of client building, then just start off finding people to work for you. In a year max you'll simply act as a middle man and a quality assurance person. Open source what?

Thirdly, very good programmers often enjoy working on open source products far more complicated than a forum. Let's face it, anyone with 1 year of commercial PHP experience and no prior computer science education can sit down and write a forum. It's not difficult at all. It is, however, a lot of boring code.

I'm truly astonished.. fudforum, smf, punbb, phpbb, vbulletin, every one of them is pure spaghetti.

Surely someone has written something decent?

How is using global variables directly related to spaghetti code?

"Never imagine yourself not to be otherwise than what
it might appear to others that what you were or might
have been was not otherwise than what you had been
would have appeared to them to be otherwise."

I don't think the use of globals in PHP is not always a bad thing. There are instances where it just makes sense. For example the database class in most PHP software is used almost globally in everything. Now you can pass it all your other classes as params on the constructor or you can use global. Either way you are producing the same effect

Taken from wikipedia even

However, in a few cases, global variables can be suitable for use. They can be used to avoid having to pass frequently-used variables continuously throughout several functions

However use of many globals is probably a bad idea but some things like your $db maybe a function class are going to be passed one way or another.

For example method without globals if I made a syntax error sue me I'm just getting my point across.

PHP Code:

class Thread
{
function Thread(&$db)
{
$this->db=$db;
}
}

Method with a global

PHP Code:

class Thread
{
function Thread()
{
global $db;
$this->db=$db;
}
}

Of course this also depends on how you designed your database class.

Reading more I seem some of the most uneeded practices I've ever seen. Yeah I'm going to never grab $_POST, $_GET ect.

What exactly are you accomplishing by this you could say add things to do basic checks. Your form data however will always be different and they all may have different constraints. So in the end of it you've added overhead for something so simple. This thing probably would also have one for say $_GET, $_COOKIE ect.

But hey you guys know best but don't seem to be pumping out your own forum.

Of course I'm one to talk I have yet to complete mine but I'm only one person. Of course when I do finish and someone asks about it I'm sure it'll be hated on for some bad practice of some kind by the "experts".

However use of many globals is probably a bad idea but some things like your $db maybe a function class are going to be passed one way or another.

The other being... Dependency Injection!

Now, seriously, I don't think there's a good reason to build a class that initializes itself from globals such as you posed. There are tons of ways to get around arduously passing the database connection instance to the constructor. And is it really that bad anyway? Applying a bit of DRY gets you a long way.