在循环中,我希望有一个特征来填充成员变量。
问题:
IDE告诉我:
不再支持带大括号的数组和字符串偏移访问语法。
我的代码
use CustomTrait;
private function mapUserData($mapping, $userData){
foreach($mapping as $owerKey => $theirKey) {
$this->set{$owerKey} = $userData[$theirKey];
}
}发布于 2021-12-16 11:38:00
发布于 2021-12-16 11:37:22
试=
<?php
class Test
{
use CustomTrait;
private function mapUserData($mapping, $userData): void
{
foreach ($mapping as $owerKey => $theirKey) {
$methodName = "set{$owerKey}";
// check method
if (!\method_exists($this, $methodName)) {
continue;
}
$this->{$methodName}($userData[$theirKey]);
}
}
}https://stackoverflow.com/questions/70378271
复制相似问题