Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a php class code like this:

class Foo{
  const ERROR_CODE = '404';
  public $public_ex = 'this is public';
  private $private_ex = 'this is private!';
  protected $protected_ex = 'this should be protected'; 
  public function getErrorCode() {
    return self::ERROR_CODE;
  }
}
$foo = new Foo;
$foo_json = json_encode($foo);
echo $foo_json;

And it shows:

Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in xxx.php on line 4

What should I do to make it run? Thank you very much!! > <

share|improve this question
    
Cannot replicate the error you've give with the code provided. Unless you're running <5, but then again, not the same error. –  ʰᵈˑ Nov 3 '14 at 11:29
    
Which line is #4 in the original file? There are no problems associated with your private variable example as listed above. Is this the entire file or just part of it? –  Maxim Kumpan Nov 3 '14 at 11:31
    
I tried your code and it works for me... is the parse error in this code or in a different file? which file is xxx.php? –  Ares Draguna Nov 3 '14 at 11:36
    
Show us your xxx php, because the code you posted is valid php code. –  lolka_bolka Nov 3 '14 at 11:42
    
It's the code of xxx.php...Orz It seems like it only doesn't work for me..(?) T_T –  Elsa Nov 4 '14 at 2:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.