How to Cast Objects in PHP

后端 未结 12 1946
轮回少年
轮回少年 2020-11-27 04:24

Ive some classes that share some attributes, and i would like to do something like:

$dog = (Dog) $cat;

is it possible or is there any gener

12条回答
  •  旧巷少年郎
    2020-11-27 04:50

    It sounds like what you really want to do is implement an interface.

    Your interface will specify the methods that the object can handle and when you pass an object that implements the interface to a method that wants an object that supports the interface, you just type the argument with the name of the interface.

提交回复
热议问题