0

I am getting the following error:

Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'

The referenced lines are:

class Food {

private $q = array();   
private $nutrients = array();

...

How can I fix this error?

2
  • 1
    What version of php are you using? What line of code is throwing the error? Commented Jun 18, 2009 at 6:18
  • The quoted lines are fine. Parser errors are never accurate, try posting a bigger excerpt that, when saved and executed in a file of its own, results in the same error. Commented Jun 18, 2009 at 6:19

4 Answers 4

6

you can only use "private" in a php 5 environment. It looks like you're running that in PHP 4.

Sign up to request clarification or add additional context in comments.

1 Comment

I double-checked what version of PHP I was using, and it was PHP4! I switched it to PHP5 and it works now. Thanks!
0

I think you're missing an ending curly brace '}'. (at least you did in the provided code).

But it's hard to tell with as less code as you provided. Please provide more code on the issue.

Comments

0
class Food {

private $q = array();
private $nutrients = array();

}

Comments

0

This is likely to be caused by a string that is declared further on in your class somewhere outside any function calls or variable declarations.

Another likely cause is a missing semicolon on the end of one of your declarations.

Can you please provide more code (including the offending line number).

Comments

Your Answer

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