Andrew Woods on Nostr: today in OOP in PHP: I have a base class Entity with a save method class foo extends ...
today in OOP in PHP:
I have a base class Entity with a save method
class foo extends Entity it redefines save() and calls parent::save() within.
Class Bar extends Foo
but I don’t like foo::save. I want to skip it entirely. So in Bar::save i try to call parent::parent::save(). This doesn’t work, but I wish it did. Instead i need to call Entity::save() the grandparent class
Is there a reason (eg performance, design) why parent::parent::save doesn’t work?
#PHP #OOP
Published at
2024-08-31 00:38:06Event JSON
{
"id": "ab207a39ea97b5dc58459cd233a2e8b90c0bc2a0d16994220e313ed550c36f6c",
"pubkey": "d1c57757ad22b24d62a0357f385b931e402073e2028f3a8142e094b6bf8d1c6f",
"created_at": 1725064686,
"kind": 1,
"tags": [
[
"t",
"php"
],
[
"t",
"oop"
],
[
"proxy",
"https://phpc.social/users/awoodsnet/statuses/113053839298952208",
"activitypub"
]
],
"content": "today in OOP in PHP:\n\nI have a base class Entity with a save method\n\nclass foo extends Entity it redefines save() and calls parent::save() within.\n\nClass Bar extends Foo\nbut I don’t like foo::save. I want to skip it entirely. So in Bar::save i try to call parent::parent::save(). This doesn’t work, but I wish it did. Instead i need to call Entity::save() the grandparent class\n\nIs there a reason (eg performance, design) why parent::parent::save doesn’t work? \n\n#PHP #OOP",
"sig": "5665a0074c13b67af2f7f7a81194bdeb97c772079fbafa7d311886f7adf34502a0cf369e2be4aef655f03911ba4940412cb120d2dc5983b3c2e88ee9da143430"
}