0

i wrote a small program to help me study, it works fine on the localhost, but when i upload it i get an error message that has me stumped

the line i get the error with is below

<?php echo "Num #  : " . ($_SESSION['monster']->getQuestionNumber()[$q]) ."&nbspof&nbsp". $_SESSION['monster'] -> getTotalQuestions() . "<BR>";?>

on the local host i have PHP Version 5.4.4-14+deb7u5

on the remote server i have PHP Version 5.2.6

the error i get is

 Parse error: syntax error, unexpected '[' in /xxx/xxx/xxx/xxx/user/htdocs/quizzme.php on line 57

any ideas

9
  • Yes; your remote php version doesn't support that syntax. Commented Nov 17, 2013 at 22:03
  • 1
    php < 5.4 do not support array dereferencing Commented Nov 17, 2013 at 22:03
  • It's called array dereferencing, and was introduced in PHP 5.4 Commented Nov 17, 2013 at 22:03
  • 1
    I'm not sure why nobody has mentioned this yet, but this is called array dereferencing and was introduced in PHP 5.4. See Example #7. Commented Nov 17, 2013 at 22:03
  • 1
    @Pekka웃 There's something about dereferencing in one of the answers now. Perhaps that'll help. Commented Nov 17, 2013 at 22:07

1 Answer 1

2

Array dereferencing is not supported on the earlier version of PHP. You need to do something like this:

<?php 
    $temp = $_SESSION['monster']->getQuestionNumber();
    echo "Num #  : " . $temp[$q] ."&nbspof&nbsp". $_SESSION['monster'] -> getTotalQuestions() . "<BR>";
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a million, really appreciate your swift answer, works a treat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.