Trying to access array offset on value of type bool

Author: Poonam

When upgrading php from php 7.4 to php 8.0 an error generally comes which says – “Error Trying to access array offset on value of type bool” .

There is a very simple fixes for this error.

Check for the mentioned file and the line and check for the array valiable.

This error comes when we use array offset which is not having any value i.e false. To remove this error we need to add a check for the value in this array variable like below:

$featured_img_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');

if( $featured_img_url ){
    $thumb_url = $featured_img_url[0];
}else{
    $thumb_url = '';
}

Modify your codes according to this sample codes.

Hope this will solve the issue. If you still face the issue let us know.

Share on: Share Poonam yogi blogs on twitter Share Poonam yogi blogs on facebook Share Poonam yogi blogs on WhatsApp Create Pin in Pinterest for this post

Comments

  • jams says:

    Excellent
    These codes can also be used for adding featured image in the page

    $featured_img_url = wp_get_attachment_image_src( get_post_thumbnail_id(), ‘full’);

    if( $featured_img_url ){
    $thumb_url = $featured_img_url[0];
    }else{
    $thumb_url = ”;
    }

    echo $thumb_url; // to display featured image in the page


Please give us your valuable feedback

Your email address will not be published.

How to Install and configure Webmin on CentOS 8
How to Install and configure Webmin on CentOS 8

Webmin is an open-source control panel that allows you to manage your Linux server through an easy-to-use web interface. It allows to manage users, groups, disk quotas, create files and directories as well as configure most popular services including web, FTP, email and database servers.

Read full article
Cloud9 IDE git Installation on Debian
Cloud9 IDE git Installation on Debian

Regardless of whether you are a solitary engineer or a group with numerous designers, Cloud9 is a simple to utilise, adaptable, cloud IDE. Cloud9 might meet your requirements, as it is a self-facilitated programming bundle that permits you to create in the cloud.

Read full article
Whatsapp web detailed guide
Whatsapp web detailed guide

WhatsApp Web and Desktop
There are two options for using WhatsApp on your computer:
WhatsApp Web: It is a browser-based application of WhatsApp, with this you can use a web browser for accessing WhatsApp.

Read full article
How to unlock your locked snapchat account
How to unlock your locked snapchat account

Do you feel like your Snapchat is suddenly acting weird? Are you facing any interruptions while using Snapchat?
Or Are you unable to use all the features of Snapchat?
In case, you are dealing with the above situations or similar.

Read full article

Some important study notes