• Resolved ruthvant2022

    (@ruthvant2022)


    I have this code linking to AFC gallery, it took me a while to make it work initially, it works perfectly in PHP 7.4, but causes a fatal error in PHP 8. Is there anything obvious to you that might do this?

    <!--Gallery Tag Lighbox Code//-->
    <div class="centerWidth popupGallery">
    <?php $images = get_field('pop_up_gallery');
    $size = 'square'; // (thumbnail, medium, large, full or custom size)
    $url = $image['url'];
    $title = $image['title'];
    $alt = $image['alt'];
    $caption = $image['caption'];
    if ($images): ?>
    <ul id="galleryList">
    <?php foreach($images as $image_id): 
    $content = '<li class="list-inline-item">';
    $content = '<a class="gallery_image" href="'. wp_get_attachment_url($image_id, $url).'">';
    $content = '<div class="galleryPhoto" style="background-image:url('. wp_get_attachment_url($image_id, $size) .');"></div>';
    $content = '<div class="galleryTitle"><p>'.wp_get_attachment_caption($image_id, $caption).'</p></div>';
    $content = '</a>';
    $content = '</li>';
    if ( function_exists('slb_activate') ){
    $content = slb_activate($content);
    }
    echo $content; ?>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>			
    </div>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Archetyped

    (@archetyped)

    Hi, what is the error message you are receiving when running under PHP 8? That should provide details on what the issue is.

    Thread Starter ruthvant2022

    (@ruthvant2022)

    Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /home/tmpadev1co/public_html/wp-content/themes/Portico/single-properties.php:49 Stack trace: #0 /home/tmpadev1co/public_html/wp-includes/template-loader.php(106): include() #1 /home/tmpadev1co/public_html/wp-blog-header.php(19): require_once(‘/home/tmpadev1c…’) #2 /home/tmpadev1co/public_html/index.php(17): require(‘/home/tmpadev1c…’) #3 {main} thrown in?/home/tmpadev1co/public_html/wp-content/themes/Portico/single-properties.php?on line?49

    this is line 49

    $url = $image[‘url’];

    • This reply was modified 1 year, 10 months ago by ruthvant2022.
    Thread Starter ruthvant2022

    (@ruthvant2022)

    Oh I’ve just tried it without the variable in brackets and it works! So only need this

    <!--Gallery Tag Lighbox Code//-->
    <div class="centerWidth popupGallery">
    <?php $images = get_field('pop_up_gallery');
    $size = 'square'; // (thumbnail, medium, large, full or custom size)
    $url = $image['url'];
    $title = $image['title'];
    $alt = $image['alt'];
    $caption = $image['caption'];
    if ($images): ?>
    <ul id="galleryList">
    <?php foreach($images as $image_id): 
    $content = '<li class="list-inline-item">';
    $content = '<a class="gallery_image" href="'. wp_get_attachment_url($image_id, $url).'">';
    $content = '<div class="galleryPhoto" style="background-image:url('. wp_get_attachment_url($image_id, $size) .');"></div>';
    $content = '<div class="galleryTitle"><p>'.wp_get_attachment_caption($image_id, $caption).'</p></div>';
    $content = '</a>';
    $content = '</li>';
    if ( function_exists('slb_activate') ){
    $content = slb_activate($content);
    }
    echo $content; ?>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>			
    </div>
    Plugin Author Archetyped

    (@archetyped)

    Something must be wrong with this forum’s formatting because the updated code block looks exactly the same as the code in your original post, but I’m glad your issue was resolved ??

    For future reference, checking PHP’s website before upgrading to a different version is recommended, as they provide full details on the changes between versions, especially on changes that may affect compatibility with code written for older versions of PHP.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘PHP 8 Problem’ is closed to new replies.