I come from Pascal, Java, and then Python. I look forward to learning Ruby, Lisp (Clojure & Scheme), and C. I plan to learn Javascript too. Amongst all languages, I also decided to learn PHP.

I should clearly state this up front: I know that PHP sucks.

Well, the fact that a language sucks shall not - at least not directly - infer that one should not learn it. (By "learn it", I mean "know about it enough so that you are capable of working in a project that uses it".) I decided to learn PHP simply because it's unfortunately just too widely used. I want to be able to understand metaphors mentioning PHP, and I want to be able to understand some projects written in PHP. Of-course I won't use PHP to build anything from my inspiration, nor to teach others to program.

I feel, that: Learning PHP is hard, because it bends your instincts. Using PHP is also hard, because you never know where the next unexpected ridiculous gotcha, coming from the core of the language itself, will pop up.

I've learnt a tiny bit, and have just come across this:

$foo = "This variable is global";

function my_func() {
    return $foo;
}

echo my_func();
// echoes empty string

WTF?

Turns out, that the "return" statement's operand silently created an uninitialized local variable that shadows the global one.

Obviously, this seems like one of the most trivial gotcha's in the fractal of PHP; but I do feel like I need at least one example in order to make a point.

 

Take the concept "function" for example. This very concept is a mental/expressive/computational tool created for a purpose: to hide details and create an abstraction. Functions (outside of PHP!) work the way they do - e.g. being able to refer to variables defined outside itself - because such a way helps the concept of "function" suit its purpose. (As for how that helps, I'd rather not explain - it doesn't belong in this article. Besides, I could've used an example other than "function" right?)

Programmers learn language-independent abstract programming/computation concepts - such as "function" - and, relying on those concepts, gain intuitive instincts of ways to think about, or solve, problems. (In jargon: those concepts provide programmers an abstraction barrier on top of tools for solving problems.) Such instincts - or say, mindsets - are shared between different programming activities. The mindset is programming.

 

PHP doesn't seem to give a shit about those mindsets. Who cares if you expect global variables to be accessible inside functions or not? In fact who cares if they are meant to be accessible or not? As long as you, the unlucky programmer who needs to use PHP, can search the fucking PHP manual and see that "ah, so in order for things to intuitively make sense, I have to artificially adapt stuff", PHP is usable (whatever that means). Thus here is the problem:

PHP disobeys the programming mindset.

As a result of this, those who know how to program would be astonished by PHP's nonsense every now and then, while those who do not yet know would subconsciously receive a set of intuition that's simply bad for the purpose of programming - a set intuition that will cause incapability to appreciate or make use of all those abstract concepts created by previous contributors to computation and programming, computer science and maths, due to being it being incompatible with them. (Note, that PHP does not provide any intellectually worthy mindset, if any non-conflicting mindset at all. That would be a miracle.)

Of-course one does not simply either do or don't know how to program - one rather hold a dynamically-changing arbitrary set of conceptual knowledge instead. The amount of damage PHP does to its learner/user depends on the amount of conceptual programming knowledge he has: the more he already knows, the less the damage; the less he already knows, the more the damage.

As a conclusion, which tries to give myself and others some advice on exactly what attitude to hold towards PHP, and especially also to remind myself and keep myself aware of the consequences of learning/using PHP:

Learn and remember to protect yourself from potentially subconsciously learning any programming concepts from PHP.

If an intuition is unfortunately created through the learning or using of PHP, it would most likely need to be un-learned and properly re-learned through a different programming language. It is better to first learn the concept through a proper programming language, and subsequently applied in PHP.

The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence.
Edsger W.Dijkstra