Javascript modules provide some interesting features, such as encapsulation, private state, and even inheritance from other modules. Although they provide some class functions, as in PHP, they are not. They are trying to use existing Javascript functionality to emulate classes, so why confusion. those. they are built to look and feel like classes .
Javascript modules are instances of the anonymous function assigned to a variable. Therefore, they have all the functions of the function, where their code is executed from top to bottom, they have and sometimes use the return statement (in PHP classes, no statements can be executed directly, except for the definition of the field and destination) and they even have access to global variables . In PHP, on the other hand, a class, or rather methods, cannot access a variable that is not in the class itself. To access global variables, a class method or static function must explicitly call the variable ie global $a inorder to import it. All global vars are available in js-modules, but sometimes one of them selects explication, importing them for cleaner code (function(a){})(imported);
Another important issue is data abstraction. Although js modules provide private states for fields, PHP classes, like C ++, java, python, etc., provide more security for properties. It allows you to use base classes using the abstract class and interface keywords, where class methods and attributes are defined or structured, but not used.
PHP classes also have constructors and destructors that are called when the class object is initialized and, at the last mention, is used to destroy the object. Of course, you can create functions in modules to run whenever you want, in PHP, on the other hand, functions in a method are executed only when they are called either by an object, class, or other functions.
Classes have static functions, they can be called even without an object of the class and executed independently of objects, on the other hand, in js, everything is an object; which defeats the point of static functions.
They are similar: they have inheritance, where you can extend the existing module to a new one, and in PHP you can use extends to inherit the parent class. They both have private data states that prevent external access, both group and packet data and methods, and both are excellent when used correctly.