我有一个与我的ChampionshipSettings Class
的属性相匹配的数组所以,我需要我的数组作为ChampionshipSetting对象
我唯一能做的就是:
$settings = $championship->settings ?? (object)$mySettings;
但是$ settings是一个Object,而不是ChampionshipSettings对象
如果我尝试:
$settings = $championship->settings ?? (ChampionshipSettings)$mySettings;
我收到语法错误....
任何想法???
答案 0 :(得分:2)
您可以创建一个新对象:
$settings = $championship->settings ?? new ChampionshipSettings($mySettings);