I see constant references to the " Way," such as descriptions of a particular framework or application as "Pythonic," a certain person as a "Perl hacker," or "true Ruby code," but where are the "PHP hackers," the "PHP-ic" applications, the "true PHP style"?

This made me think - does PHP even have a definite style? Saying PHP is easily "changeable" to other styles doesn't count, as the same goes for any reasonable language.

Any input much appreciated.

  • 3
    "If it still works, it ain't finished" Commented Aug 9, 2011 at 13:07
  • quora.com/How-does-a-programmer-become-a-brogrammer - perhaps we could call it "PHmoronic"?
    – psr
    Commented Aug 10, 2011 at 21:20
  • As a PHP programmer of about 20 years now, I've never heard of "the PHP way", but it reminds me of phptherightway.com. Commented Mar 14, 2022 at 21:41

7 Answers 7


Unlike many other programming languages, PHP doesn't have a unifying thought or a set of core ideas: it started as a very pragmatic set of perl scripts, and features were added as needed, without much of a formal design process. The result is a language that is quite useful and complete, but not very consistent by itself. The immense popularity of the language makes things worse; as soon as a new feature is introduced, it is practically set in stone, because everyone starts using it. A few design mistakes have thus been consolidated, and the PHP team has a really hard time getting people to walk away from them - register_globals and magic_quotes are just two examples of things that seemed like good ideas at the time but turned out rampant.

Another factor is the culture that grew around PHP. When its popularity began to grow, the typical use case for PHP was to add little snippets of server-side functionality into otherwise static HTML documents. A large part of the target audience was hobbyists and non-programmers who used PHP to add a bit of dynamic stuff to their static web sites. The resulting culture is very pragmatic, without much interest in establishing a 'proper way'; while it is possible to write quite elegant PHP, a large part of the user community simply doesn't take much interest in it, as long as it works.

By contrast, languages like python, ruby, Lisp, C#, Haskell and others have had a philosophy right from the start, and the community generally embraces it and pushes the language to live up to it. (In case you're interested, type import this in an interactive python session). Having a philosophy means there's a guideline for using and extending the language, and it also leads to a more homogenous community - if you don't agree with the philosophy, you're more likely to just walk away and find one that fits you better; the resulting community is more likely to reach consensus over all sorts of things.

That said, PHP does have strengths and weaknesses, as well as obscure edge cases; writing idiomatic PHP code means using the strengths and avoiding the weaknesses and obscurities, just like with any other language.

  • In what way is php not consistent? The sheer simplicity of the language leads to an extremely orthogonal language you never have to guess at what syntax to use. In particular complex data structures (trees, linked lists, edge graphs) are handled almost as well as in Python and certainly better than in Java or C++ STL. Commented Aug 10, 2011 at 1:42
  • 3
    PHP puts everything in the global namespace; the various API functions use different naming conventions, some of them modify their arguments in-place while others in a similar situation return the modified argument, only half of its string functions are available as mb_XXX() versions, there's three kinds of variables with different scoping rules, you call a function to define a constant, you can (but don't have to) call a function to create or read a global variable, I could go on for ages.
    – tdammers
    Commented Aug 10, 2011 at 7:15
  • @tdammers PHP does not place "everything" in global space, while many functions are in global namespace, many others aren't - see, for example, PDO or SPL. Global, local and static variables exist in many languages and in no way unique to PHP. You can define constants without calling a function. You can write a function which accesses globals (it's kind of the point of having globals) but there's absolutely nothing wrong with that.
    – StasM
    Commented Aug 10, 2011 at 9:20
  • I think that for the simple reason that this answer actually provides backing to its claims it should be selected as Best Answer, but the other answers were very helpful too (and helped me realized how much argument a question like this can bring!) Commented Aug 13, 2011 at 21:39

I think when people say the PHP-way, it has negative weight attached to it, that's the term we used in a polygot shop (Python, C#, Ruby). Such as "just-do-it-and-throw-it-out there", as in it could have goto's, leaking file handles, SQL injection vulnerabilities, super deep nested loops, 3000-line functions and still be classed as the 'PHP-way'. If in a peer review someone said to me that the code is very 'PHP-way', I would be deeply offended.

I appreciate this will cause some flames, so I will acknowledge that there has been people known to produce good PHP code, and PHP is used in some major production sites. I'm just saying what the crowd thinks and sees most often, the opinion is carried by the acts of the majority, not the minority.

  • 5
    Funny thing is all you mentioned has absolutely nothing to do with PHP - and until recently it didn't even have goto, so there's no possibility there's so much PHP code out there with goto's that it gave the name to a distinct style.
    – StasM
    Commented Aug 9, 2011 at 6:48
  • StasM one can create a monster of unmaintable, insecure or poor performing (or a mixture of all) in any language. The VM/interpreter nowadays is rarely the problem. What am I saying is that PHP low barrier to entry, global namespace pollution and other features/downsides of the languages seem to attract a crowd of throw-it-together-anyway and hence the reputation. Its an undeniable reputation, I was just trying to shine some light that on it
    – sa93
    Commented Aug 9, 2011 at 7:22
  • StasM, you missed the point, I never said it would include gotos.
    – sa93
    Commented Aug 9, 2011 at 7:24
  • 3
    @sa93 - I'm a big php fan, and have been using it since php3. StasM is pretty much correct - most people think of PHP output as poor. This is for a good reason, most of it is. Just need to live with that, on the plus side, it makes it quite easy to shine in php contracting.
    – Jonno
    Commented Aug 9, 2011 at 8:07
  • I seen a lot of J2EE code which is much worse than any php code I have seen. Commented Aug 9, 2011 at 8:51

If there is a "php way" its "Just get it done!".

Although php has all the modern OO constructs Classes, Modules Name Spaces, Introspection etc. plus all of the dynamic programming goodies usually associated with more fashoinable languages such as Python. You seldom see them used just for the sake of it, or, see php programmers obsess over the "purity" of their implementation.

I have no idea why there should be such a cultural difference -- but there it is there.

There are a number of horrors out there and this perhaps reflects that so much "php" code is "My First Webapp" or even "My First Program".

Personally I find it pretty easy to read/understand professionally written php code, generally it much easier to read than Java apps will all its Factory classes and half the logic in XML files.


I would say the PHP way is the "Duct Tape Programmer" - ship it quick, ship it fast, worry about everything else later and quick patch bugs without thinking to the future. While that's in no way a condemnation of PHP itself (you can do that in any language), it's only been recently that PHP developers have begun to wonder about software engineering and design patterns, SOLID, testing, and the like.


I'd say the idea of PHP it's being practical. What it means in each separate case it's hard to define, but for example if doing something requires one HTML form and five lines of code, don't put MVC framework with 20 classes there. And, conversely, if you develop application for 20 million people to use, do put the framework there and have logic, presentation and flow control separately. But there's nothing special about PHP here, so I guess it may be not a satisfactory answer.

I don't think there's one PHP style. I personally think that the notion that there's one style which fits all language users makes sense only if the language has very restricted field of usage, which is definitely not true for PHP.

Specific applications have their styles - for example, if you look into Zend Framework, you'll see very OO code with defined interfaces, controlled APIs, etc. where you could readily recognize familiar design patterns. On the other hands, there are applications taking more procedural approach, like Drupal.

I understand that doesn't give you much of "true PHP style", but that's probably because there's no such thing. There are best practices, etc. but it's not what you are looking for, I'm afraid.


Some people do use php as a mark of disdain - just a fact, personally I'm a fan.

However for me the thing that defined a php approach is the essentially the lack of application context. There is no built in application context compared to .NET or the Java world.

This leads to php servers being essentially stateless (as long as sessions are moved out to another server e.g. shared disk or db)

This is pretty much what I think of when I think of the php way.


Another answer! This time its more of an observation on the "culture" of programming.

PHP is in the same position as Javascript (ECMAscript to pedants!) was in about 2002. A small group of expert programmers appreciated its excellence bit the general opinion was that it was a poor and obscure scripting language useful only for scrolling banners and annoying users with popups.

Then along came AJAX and suddenly the whole world was in awe of the power and elegance of Javascript.

While not actually as elegant as Javascript, php does share a lot of the power and simplicity of that language, and there is a gathering consensus on the "correct" way to program php for large systems.

The other indicator of how good php is in its specialist sphere is the lack of frameworks for most serious applications a lot of very experienced programmers are happy to just use "php" as it stands without the aid of some mega framework. The sheer proliferation of frameworks and other aids indicates to me that Java, Python etc. did not get it right and that programmers using these languages are deeply unhappy and unsure about how a web application should be created. Yet when they see how pure simple php code is used to successfully implement complex web sites without the unreadable XML configurations, the template dialect of the month, or, the roll your own ORM dialect they draw the wrong conclusion -- that the php must be bad because it doesn't have an IntegerFactory classes, dependency injection etc. etc.

In fact all of these things are easily implemented in php and are often used if required -- its just that the implementation is usually a couple of lines of php and is not recognized as such by programmers who are used to doing the same thing with massive libraries and complex APIs.

php is simple. "simple" is the highest complement you can give a piece of software and the hardest to achieve.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.