我有一些像這樣的代碼:從空值在PHP創建默認對象5.4
function getAuthorizedPFComponents($pfState)
{
$authorizedPFComponents = new \stdClass();
$compTypeMap=array('platform'=>'pfAuthorizations','mainSite'=>'mainSiteAuthorizations','microSites'=>'microSiteAuthorizations','apps'=>'appAuthorizations');
foreach($compTypeMap as $compType=>$tagName)
{
$authorizationsNode=$this->pfAuthXMLDOM->getElementsByTagName($tagName)->item(0);
foreach($authorizationsNode->getElementsByTagName('authorizations') as $pfComponentAuthElem)
{
foreach($pfComponentAuthElem->getElementsByTagName('allow') as $allow)
{
switch($allow->getAttribute('orgCode'))
{
case 'K_ALL':
{
$authorizedPFComponents->$compType->{$pfComponentAuthElem->getAttribute('pfComponentCode')}->storeCode=$allow->getAttribute('storeCode');
}
}
它顯示了一個警告:
Warning: Creating default object from empty value
的警告case K_ALL:
歡迎來到SO!您的問題缺少一些細節,例如錯誤來自哪裏? –
它顯示最後一行錯誤,即$ authorizedPFComponents - > $ compType - > {$ pfComponentAuthElem-> getAttribute('pfComponentCode')} - > storeCode = $ allow-> getAttribute('storeCode')它說試圖創建來自空值的默認對象 – user1823249