0

I am trying to set up an image gallery portfolio on my website based on this template.

However, the PHP code for the gallery is not loading properly. I get the following error:

Parse error: syntax error, unexpected ':', expecting '{' in [URL]/templates/gallery.php on line 6

This is the relevant part of the gallery.php code, line 6 being were the function "createThumbs" is defined:

// loop through each project, and for each of it's thumbnails, create a HTML for a thumbnail linking to that project.
function createThumbs($projects, $sectionName, $ROOT, $ORTFOLIO_LOCATION): array {
  $thumbdivs = array();
  foreach ($projects as $project) {
    $projectName = basename($project);
    $projectPath = "/".$sectionName."/".$projectName;
    $thumbs = glob($ROOT ."/".$projectPath."/thumbnail/"."*.{jpg,jpeg,gif,png}", GLOB_BRACE);
        
    foreach ($thumbs as $thumb) {
      $thumbdivs[] = sprintf('<div class="grid-item">'.PHP_EOL.'<a href="%s">
    <img src="%s" alt="%s"></a></div>'.PHP_EOL, 
      $ORTFOLIO_LOCATION.$projectPath,
      $ORTFOLIO_LOCATION.$projectPath."/thumbnail/".basename($thumb),
      basename($project));
    }
  }
  return $thumbdivs;
}

I suspect the problem comes from the fact that my web hosting server is running php 5.6, and this code is not suitable for this version. How could I modify it to make it work?

Paul Miller
  • 493
  • 1
  • 5
  • 13
  • Yes you're correct. You _could_ just remove `: array`, but far better advice would be to urgently upgrade your out of date php to a supported versio so you can continue to receive security updates and new features. If this is a live server then running such outdated software is somewhat irresponsible – ADyson Nov 20 '22 at 20:24

0 Answers0