Question

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

Was it helpful?

Solution

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>";
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top