i was searching in the internet for a way to do downcasting in PHP, but i couldn't find any thing useful, does PHP support it? if not, is there a way to achieve that?
Asked
Active
Viewed 948 times
0
-
@nice_dev https://en.wikipedia.org/wiki/Downcasting – Malek Alhourani Jan 09 '21 at 08:59
-
1Cast operator does not accept class names. You cannot convert an object across classes. – Álvaro González Jan 09 '21 at 09:09
-
There isn't a way in PHP, it throws an error as of now. – nice_dev Jan 09 '21 at 10:18
-
Regarding the "is there a way to achieve that" part, you basically need to create an instance of the target class and copy the properties you want. You can make it as ingenious as you want but it's basically a manual hack for an unsupported feature. – Álvaro González Jan 11 '21 at 14:37