PHP developers hate him! Find out these weird tricks they don’t want you to know!
There are plenty of ways to make PHP developers dislike you. I would know, because I do it all the time. Not by sharing the infamous “fractal of bad design” article (which is something that only programmer boomers do) but by writing awful code.
In the real world, . That’s not the case in the programming world. When it’s about keeping private things private, keep in mind that nothing’s really private: “private” is at best “public with a few extra steps”.
Let’s say we have an Account
class with a private $balance
property and a
private method close()
. Normally, neither are accessible from the outside:
Of course you can use reflection to access the $balance
anyway, but that
typically requires a whopping four lines of code that can be somewhat cumbersome
to write:
However, we can also take advantage of the fact that lambda functions have
access to $this
, and that they can be invoked on arbitrary objects. This
allows us to simply write a lambda that returns $this->balance
of $account
:
This notation also allows us to set private properties:
or call private methods:
Reserved keywords and standard libraries are typically in English, and consequently most code is written in English as well. This already greatly limits the amount of possible identifiers for things like classes, functions, and variables. But to make matters worse, most programming languages only allow you to use alphanumeric characters and maybe hyphens or underscores. Some, like Kotlin even allow you to use spaces for test methods.
Although PHP hasn’t quite reached that level of enlightenment yet, there’s a lot you can do. For example, you can totally use non-breaking spaces in identifiers, even if your syntax highlighter disagrees with you:
You can also use other non-alphanumeric characters from languages other than English:
This also includes emojis of course:
It even includes Zalgo text:
Very few PHP programmers encounter goto statements in the wild. This is largely because as everyone knows, goto statements are considered harmful. Consequently, programmers and programming language designers have done a pretty good job at removing goto statements entirely from all languages and codebases.
Well, not entirely… Some programming languages still hold out against the idea of structured programming. This includes PHP, where the goto statement is not only supported in the latest version, but even alive and kicking in popular libraries like Flysystem!