How to Cast Objects in PHP

后端 未结 12 1965
轮回少年
轮回少年 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:46

    You can opt for this example below. Hope it will help.

    /** @var ClassName $object */
    
    $object->whateverMethod() // any method defined in the class can be accessed by $object
    

    I know this is not a cast but it can be useful sometimes.

提交回复
热议问题