提问人:A. Cedano 提问时间:11/6/2023 更新时间:11/6/2023 访问量:46
“未知命名参数”难以理解的错误
"Unknown named parameter" incomprehensible error
问:
我正在构建几个非常相似的对象,它适用于所有对象,除了一个。
错误跟踪为:
Fatal error: Uncaught Error: Unknown named parameter $hymnus in /THEROUTE/src/App/Models/Completorium.php:27 Stack trace:
#0 /THEROUTE/src/App/Domain/Infrastructure/Mapper/Breviarium/PdoBreviariumMapper.php(397): App\Models\Completorium->__construct('completorium', Object(App\Models\Kyrie), Object(App\Models\Hymnus), Object(App\Models\Psalmodia), Object(App\Models\LectioBrevis), Object(App\Models\CanticumEvangelicum), Object(App\Models\LHOratio), Object(App\Models\Conclusio))
#1 /THEROUTE/src/App/Domain/Infrastructure/Mapper/Breviarium/PdoBreviariumMapper.php(47): App\Domain\Infrastructure\Mapper\Breviarium\PdoBreviariumMapper->completorium(Object(stdClass))
#2 /THEROUTE/src/App/Domain/Infrastructure/Repository/Breviarium/BreviariumRepository.php(21): App\Domain\Infrastructure\Mapper\Breviarium\PdoBreviariumMapper->getData(Array)
#3 /THEROUTE/src/App/Domain/Service/Breviarium/BreviariumService.php(36): App\Domain\Infrastructure\Repository\Breviarium\BreviariumRepository->getData(Array)
#4 /THEROUTE/src/App/Controllers/Home.php(44): App\Domain\Service\Breviarium\BreviariumService->getData()
#5 [internal function]: App\Controllers\Home->getFromServerAction()
#6 /THEROUTE/src/Core/Controller.php(48): call_user_func_array(Array, Array)
#7 /THEROUTE/src/Core/Router.php(124): Core\Controller->__call('getFromServer', Array)
#8 /THEROUTE/index.php(57): Core\Router->dispatch('')
#9 {main} thrown in /THEROUTE/src/App/Models/Completorium.php on line 27
代码的相关部分:
PdoBreviarium映射器
该行是:,我在以下位置正确传递了一个命名参数:397
new \App\Models\Completorium(
hymnus
hymnus: new \App\Models\Hymnus("Lorem ipsum"),
new \App\Models\Completorium(
typus: $r->hora,
kyrie: new \App\Models\Kyrie($r->kyrieID,$r->kyrie),
hymnus: new \App\Models\Hymnus("Lorem ipsum"),
psalmodia:
new \App\Models\Psalmodia(
$r->psalmodiaTypus,
(object) [
'antiphons' => $r->antiphons,
'psalmus' => $r->psalmus,
'psalmusPericopa' => $r->psalmusPericopa,
'epigraphs' => $r->epigraphs,
'themes' => $r->themes,
'parts' => $r->parts,
]
),
lectioBrevis:
new \App\Models\LectioBrevis(
$r->lectioBrevis,
$r->brevisPericopa,
new \App\Models\ResponsoriumBrevis(
$r->brevisResponsorium,
$r->brevisResponsoriumTypus)
),
canticumEvangelicum:
new \App\Models\CanticumEvangelicum(
6,
array(new \App\Models\Antiphona(0,$r->canticumEvangelicum))),
oratio:
new \App\Models\LHOratio($r->oratio),
conclusio:
new \App\Models\Conclusio($r->antiphonaMariam)
)
完效
该行是:27
typus:$typus,
namespace App\Models;
class Completorium extends \App\Models\LiturgiaTypus implements \JsonSerializable
{
private Kyrie $kyrie;
private LectioBrevis $lectioBrevis;
private CanticumEvangelicum $canticumEvangelicum;
private Conclusio $conclusio;
private bool $isPrimaVesperas=false;
public function __construct
(
string $typus,
Kyrie $kyrie,
Hymnus $hymnus,
Psalmodia $psalmodia,
LectioBrevis $lectioBrevis,
CanticumEvangelicum $canticumEvangelicum,
LHOratio $oratio,
Conclusio $conclusio
)
{
parent::__construct
(
typus:$typus,
hymnus:$hymnus,
psalmodia:$psalmodia,
oratio:$oratio
);
$this->kyrie=$kyrie;
$this->lectioBrevis=$lectioBrevis;
$this->canticumEvangelicum=$canticumEvangelicum;
$this->conclusio=$conclusio;
}
public function jsonSerialize():mixed{
return get_object_vars($this);
}
}
赞美诗
namespace App\Models;
class Hymnus implements \JsonSerializable
{
private string $hymnus;
public function __construct(string $hymnus)
{
$this->hymnus=$hymnus;
}
public function jsonSerialize():mixed{
return get_object_vars($this);
}
}
我不明白为什么会出现这个错误。我有其他类的类似代码可以正常工作。
答:
1赞
vodevel
11/6/2023
#1
班级呢。它在构造函数中是否有参数?\App\Models\LiturgiaTypus
hymnus
因为它也可能导致此错误:
parent::__construct
(
typus:$typus,
hymnus:$hymnus,
psalmodia:$psalmodia,
oratio:$oratio
);
评论
1赞
A. Cedano
11/6/2023
天哪,那是个错误!我错误地从另一个在其构造函数中没有参数的类扩展了该类。非常感谢!hymnus
评论
lectioBrevis
new \App\Models\Completorium(
$r