0

I am having problem with php version. My server only uses php 5.3.6 but my website files require php 5.4 and above.

Is there a way to convert the below code to be accepted by php 5.3.6?

$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' )**[0]**;


<?php       
    while ( $query->have_posts() ) : $query->the_post();

        $post_meta = $Listing->get_listing_meta(get_the_ID());
        $listing_options = (isset($post_meta['listing_options']) && !empty($post_meta['listing_options']) ? $post_meta['listing_options'] : "");
        $gallery_images  = (isset($post_meta['gallery_images']) && !empty($post_meta['gallery_images']) ? $post_meta['gallery_images'] : "");

        $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' )[0];
Alex Andrei
  • 7,315
  • 3
  • 28
  • 42
Nigel Ong
  • 11
  • 1
  • post the full code, it say missing [, more like syntax problem not related to version problem. – Teddybugs Jun 20 '16 at 06:35
  • It says "unexpected" and not "missing". There is some difference if you find an unexpected woman in your bed or you are missing your wife. PHP 5.4 Introduced some array shorthands, so this actually could be a version problem. – Marat Jun 20 '16 at 06:50

3 Answers3

0

$thumbnail = array_shift(wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' ));
would return the first element of an array for you, but are you sure that your Hoster does not offer PHP > 5.3?
5.3 is very old and even reached its "end of life". You could get more errors/incompatibilities in your code when using untested PHP version

Marat
  • 617
  • 5
  • 12
  • Hi, i agree to what you said. have advised my client to upgrade the server or change hosting provider. as final decision is with them. i have to find work around. thanks for great help it works great – Nigel Ong Jun 20 '16 at 09:09
0

Instead of

$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' )[0];

use

$thumbnails = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' );
$thumbnail = $thumbnails[0];

Good luck! =)

Pavel Geveiler
  • 128
  • 1
  • 8
0

Function array dereferencing was introduced in php 5.4.0

Previous versions will give you syntax errors, such as in your case.

Either upgrade the php version to >= 5.4.0 or change the code to remove the dereferencing.

Example for your case:

$thumbnail_temp = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'single-post-thumbnail' );
$thumbnail = $thumbnail_temp[0];

More about array dereferencing in the manual.

Alex Andrei
  • 7,315
  • 3
  • 28
  • 42