cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to access array offset on value of type null AreaList.php on line 75","1

Trying to access array offset on value of type null AreaList.php on line 75","1

I have created a custom extension but it is having issue on Magento 2.3.0 it is working fine on magento 2.3.7 or greater but having problem with Magento 2.3.0

 

"0":"Notice: Trying to access array offset on value of type null in \/home\/fmeextensions.net\/subdomains\/magento2\/administration\/agerestriction\/lib\/internal\/Magento\/Framework\/App\/AreaList.php on line 75","1":"#0 \/home\/fmeextensions.net\/subdomains\/magento2\/administration\/agerestriction\/lib\/internal\/Magento\/Framework\/App\/AreaList.php(75): Magento\\Framework\\App\\ErrorHandler->handler()\n#1 \/home\/fmeextensions.net\/subdomains\/magento2\/administration\/agerestriction\/lib\/internal\/Magento\/Framework\/App\/Http.php(130): Magento\\Framework\\App\\AreaList->getCodeByFrontName()\n#2 \/home\/fmeextensions.net\/subdomains\/magento2\/administration\/agerestriction\/lib\/internal\/Magento\/Framework\/App\/Bootstrap.php(257): Magento\\Framework\\App\\Http->launch()\n#3 \/home\/fmeextensions.net\/subdomains\/magento2\/administration\/agerestriction\/index.php(39): Magento\\Framework\\App\\Bootstrap->run()\n#4 {main}","url":"\/agerestriction\/men.html","script_name":"\/agerestriction\/index.php"

 

Any help regarding this ?

4 REPLIES 4

Re: Trying to access array offset on value of type null AreaList.php on line 75","1

Hi @hassanzami1061 ,

 

It seems like PHP version related issue.

Which PHP version are you on?

If you are not on PHP 7.3 then I suggest you to switch to PHP 7.3 and check again.

 

To resolve issue with PHP 7.4, you need to find out any array variables that you are trying to use in your module.

Before accessing you need to check it with isset($array['key'])

Like

$isAvailable = isset($arr['data']) ? count($arr['data']) : 0;

Or you can use is_array() function also.

 

Problem solved? Click Accept as Solution!

 

Hope it helps!

Thanks

Ankit Jasani

Re: Trying to access array offset on value of type null AreaList.php on line 75","1

Hello @hassanzami1061 

 

You need make changes in below file :

- vendor/magento/framework/App/AreaList.php 


Replace function getCodeByFrontName your code with below code:
    /**
     * Retrieve area code by front name
     *
     * @param string $frontName
     * @return null|string
     */
    public function getCodeByFrontName($frontName)
    {
        foreach ($this->_areas as $areaCode => &$areaInfo) {
            if (!isset($areaInfo['frontName']) && isset($areaInfo['frontNameResolver'])) {
                $resolver = $this->_resolverFactory->create($areaInfo['frontNameResolver']);
                $areaInfo['frontName'] = $resolver->getFrontName(true);
            }
            if (isset($areaInfo['frontName']) && $areaInfo['frontName'] === $frontName) {
                return $areaCode;
            }
        }
        return $this->_defaultAreaCode;
    } 

It may help you!
Thank you

Problem solved? Click Accept as Solution!

Re: Trying to access array offset on value of type null AreaList.php on line 75","1

I need to apply prefrence on AreaList.php ?

Because 

Changing core file is not a solution


@Bhanu Periwal wrote:

Hello @hassanzami1061 

 

You need make changes in below file :

- vendor/magento/framework/App/AreaList.php 


Replace function getCodeByFrontName your code with below code:
    /**
     * Retrieve area code by front name
     *
     * @param string $frontName
     * @return null|string
     */
    public function getCodeByFrontName($frontName)
    {
        foreach ($this->_areas as $areaCode => &$areaInfo) {
            if (!isset($areaInfo['frontName']) && isset($areaInfo['frontNameResolver'])) {
                $resolver = $this->_resolverFactory->create($areaInfo['frontNameResolver']);
                $areaInfo['frontName'] = $resolver->getFrontName(true);
            }
            if (isset($areaInfo['frontName']) && $areaInfo['frontName'] === $frontName) {
                return $areaCode;
            }
        }
        return $this->_defaultAreaCode;
    } 

It may help you!
Thank you


 

Re: Trying to access array offset on value of type null AreaList.php on line 75","1

I can't change the core files 


@hassanzami1061 wrote:

I need to apply prefrence on AreaList.php ?

Because 

Changing core file is not a solution


@Bhanu Periwal wrote:

Hello @hassanzami1061 

 

You need make changes in below file :

- vendor/magento/framework/App/AreaList.php 


Replace function getCodeByFrontName your code with below code:
    /**
     * Retrieve area code by front name
     *
     * @param string $frontName
     * @return null|string
     */
    public function getCodeByFrontName($frontName)
    {
        foreach ($this->_areas as $areaCode => &$areaInfo) {
            if (!isset($areaInfo['frontName']) && isset($areaInfo['frontNameResolver'])) {
                $resolver = $this->_resolverFactory->create($areaInfo['frontNameResolver']);
                $areaInfo['frontName'] = $resolver->getFrontName(true);
            }
            if (isset($areaInfo['frontName']) && $areaInfo['frontName'] === $frontName) {
                return $areaCode;
            }
        }
        return $this->_defaultAreaCode;
    } 

It may help you!
Thank you