Is it possible to employ some kind of prototypal inheritance in PHP like it is implemented in JavaScript?
This question came to my mind just out of curiosity, not that I have to implement such thing and go against classical inheritance. It just feels like a interesting area to explore.
Are there prebuild functions to combine classical inheritance model in PHP with some sort of Prototypal inheritance with a combination of anonymous functions?
Let's say I have a simple class for UserModel
class UserModel implements PrototypalInheritance
{
// setters, getters, logic..
static public function Prototype () {}
}
$user = new UserModel();
UserModel::prototype()->getNameSlug = function () {
return slugify($this->getUserName());
}
echo $user->getNameSlug();