最佳答案
因为 Model 实现了 ArrayAccess 接口(其中一个方法是offsetGet ),所以可以使用 ['xx'] 这种形式来获取属性值。两种方法都可以用,没啥问题。因为 ['xx'] 本质是调用了 getAttribute(),->xx 本质也是调用了 getAttribute()。
讨论数量:
因为 Model 实现了 ArrayAccess 接口(其中一个方法是offsetGet ),所以可以使用 ['xx'] 这种形式来获取属性值。两种方法都可以用,没啥问题。因为 ['xx'] 本质是调用了 getAttribute(),->xx 本质也是调用了 getAttribute()。
没有坑,但我想问楼主几个问题:
$a->name多少个字符?$a['name']多少个字符?$v = $a?->name多少个字符?$v = $a['name'] ?? null多少个字符?
关于 LearnKu
推荐文章: