DEV Community

Discussion on: Node vs PHP

xroal profile image
Roman Stejskal

We're arguing that PHP, which does not even have first-class support for classes (you have to use strings to pass them around, and ::class just expands to a string) is somehow more OO than JavaScript. PHP, where primitives have no attributes or methods, is more OO than a language in which basically everything is an object.

Take a look at Smalltalk, designed by Alan Kay, who coined the term "object-oriented programming". In Smalltalk, everything is an object. Number, string, file, compiler, you name it, it's an object. In fact, a class is an object which creates instances. Right.

You also don't write typical classes like in C++, Java or C#. Instead, there is an Object object which accepts a subclass message in which you describe how instances of that subclass will look like. That description itself is an object of the Metaclass class.

Smalltalk has single inheritance and every class inherits from a superclass.
The Integer class inherits from Number, which in turn inherits from Magnitude, and Magnitude inherits from Object, which is the root object. Much like prototypes in JavaScript, eh?

Also, classes, being just objects, can accept messages! There's no new MyClass construct, you send a message to the class object asking it to instantiate and return a new instance of itself.

Heck, even our well known if condition breaks OO design. In Smalltalk, a comparison like a < b gives you an object of the Boolean class which has ifTrue and ifFalse methods. There's no usual if (condition) { code } else { code } construct.

The class keyword as we know it from C++, Java, C# or PHP is not a mandate of object-oriented language. Using objects that communicate via messages and nothing but that is a mandate for object-oriented language.

PHP fails at this, and so does JavaScript. Neither of them is fully object-oriented, obviously, but I dare to say that JavaScript is much closer to what an object-oriented language looks like than PHP.