OOP

25 entries

class_alias Function Creates a runtime alias for a defined class (internal classes, interfaces and traits since 8.3) - the alias IS the same class, not a subclass. class_implements / class_parents / class_uses Function The SPL trio: the interfaces a class implements, its parent chain, and its traits, three lists in one family - the full-family portrait of inheritance relations. enum_exists Function Checks whether an enum is defined (may trigger autoloading); the enum sibling of class_exists/interface_exists/trait_exists, completing the PHP 8.1 type-table quartet. forward_static_call Function Forwards a static call down an inheritance chain while keeping late static binding (LSB): forward_static_call passes the "called class" along so static:: still resolves to the leaf subclass; a plain callback (call_user_func) falls back to the parent context. get_called_class Function Returns the class a static method was actually called on (late static binding); the functional form of static::class. get_class Function Returns the class of an object; the counterpart of instanceof - instanceof answers yes/no, get_class gives the exact name. get_class_methods Function Returns the public method names of a class or object (declaration order); the lightweight entry of the reflection family - a plain list without building a ReflectionClass. get_declared_classes / get_declared_interfaces / get_declared_traits Function Runtime class-table introspection: returns every class/interface/trait currently loaded (extension and builtin declarations included, user classes among them); no ordering guaranteed since 7.4; enums count as classes. get_object_vars Function Returns the object properties visible from the current scope - all three levels inside the class, public only outside; an object anatomy knife by visibility. get_parent_class Function Returns the parent class of an object or class, false at the root; makes the "one step up" of an inheritance chain a runtime-queryable fact. interface_exists / trait_exists Function Checks whether an interface or trait is defined (autoload may fire); part of the family with class_exists/enum_exists, a corner of PHP's runtime type table. is_a Function Checks whether an object (or a class-name string, when allowed) is of a given type or a subtype; prefer the instanceof operator for objects. Abstract classes Syntax Demonstrates abstract classes and methods; Go uses interfaces plus composition, Rust uses traits, JS relies on conventions. Classes and instantiation Syntax Defines a class with a constructor and methods, then instantiates and uses it. Class constants Syntax Demonstrates class-level constants; Python and JS have no true constants and approximate them with naming conventions and frozen objects. Object cloning and copying Syntax Distinguishes assignment by reference, shallow copy, and deep copy; Go and Rust express the same ideas with value semantics and explicit cloning. Constructors and destructors Syntax Demonstrates construction and destruction timing; Go and Rust replace language-level constructors with New/new convention functions. Enums Syntax Demonstrates enumerated types; Go simulates them with iota, JS with frozen objects, while Rust enums are the more powerful ADT. Inheritance Syntax Demonstrates inheritance and method overriding; Go expresses a similar effect with struct embedding and shadowing. Type checking (instanceof) Syntax Demonstrates runtime type checking; Go uses type assertions, Rust replaces it with enums plus pattern matching. Interfaces Syntax Defines an interface, implements it in a class, and computes the area of a rectangle. Magic methods Syntax Demonstrates property interception, dynamic invocation, and string conversion; each language approximates them with different mechanisms. Properties and methods Syntax Demonstrates private properties with methods that read and write them (encapsulation). Static members Syntax Demonstrates static properties and methods; Go substitutes package-level identifiers, Rust associated functions. Traits Syntax Demonstrates code reuse mechanisms; Python and JS use mixins, Go uses embedding, Java uses default methods.