By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,462 Members | 785 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,462 IT Pros & Developers. It's quick & easy.

php try / catch gives syntax error

P: 6
When I use the try / catch in a program I consistently get a syntax error pointing at the curly bracket after the TRY.

Is there something in the PHP5 setup that needs to be set?

Or any suggestions as to why this happens?
Jan 29 '12 #1
Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,365
We need to see the code.
Jan 29 '12 #2

P: 6
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. require 'facebook.php';
  4.  
  5. // Create our application instance
  6. // (replace this with your appId and secret).
  7. $facebook = new Facebook(array(
  8.   'appId'  => 'YOUR_APP_ID',
  9.   'secret' => 'YOUR_APP_SECRET',
  10. ));
  11.  
  12. // Get User ID
  13. $user = $facebook->getUser();
  14.  
  15. // We may or may not have this data based 
  16. // on whether the user is logged in.
  17. // If we have a $user id here, it means we know 
  18. // the user is logged into
  19. // Facebook, but we don’t know if the access token is valid. An access
  20. // token is invalid if the user logged out of Facebook.
  21.  
  22. if ($user) {
  23.   try {
  24.     // Proceed knowing you have a logged in user who's authenticated.
  25.     $user_profile = $facebook->api('/me');
  26.   } catch (FacebookApiException $e) {
  27.     error_log($e);
  28.     $user = null;
  29.   }
  30. }
  31.  
  32. // Login or logout url will be needed depending on current user state.
  33. if ($user) {
  34.   $logoutUrl = $facebook->getLogoutUrl();
  35. } else {
  36.   $loginUrl = $facebook->getLoginUrl();
  37. }
  38.  
  39. // This call will always work since we are fetching public data.
  40. $naitik = $facebook->api('/naitik');
  41.  
  42. ?>
Jan 29 '12 #3

P: 6
I am using php 5.2.17
Jan 30 '12 #4

Rabbit
Expert Mod 10K+
P: 12,365
I don't see anything obviously wrong with the code. I would double check the PHP version.
Jan 30 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.