self vs static (late static binding)
Në shqip: self dhe static në PHP
ShpjegimiSQ
self:: i referohet gjithmonë klasës ku është shkruar kodi; static:: klasës që e thirri në të vërtetë. new static() te një metodë fabrike krijon objekt të klasës bijë.
EnglishEN
self:: always refers to the class where the code is written; static:: to the class that actually called it. new static() in a factory method creates an object of the child class.
Si ta mendosh
Si dallimi mes „shkolla ku punoj“ dhe „shkolla ku jam tani“.
Lexoje në anglisht
Like the difference between “the school I work at” and “the school I'm in now”.
Shembull kodiphp
class Modeli {
public static function krijo(): static { return new static(); }
}