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

throw giving error message

P: 6
I an getting the following error:
PHP Parse error: parse error, unexpected T_STRING in errtest.php on line 7

The code is a sample from w3schools:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  //create function with an exception
  3.  function checkNum($number)
  4.    {
  5.    if($number>1)
  6.      {
  7.      throw new Exception("Value must be 1 or below");
  8.      }
  9.    return true;
  10.    }
  11.  
  12. //trigger exception
  13.  checkNum(2);
  14.  ?> 
  15.  
I am using php5 and developting on Javascripteditor
Jan 30 '12 #1

✓ answered by dlite922

I copy and pasted your code. It works as expected. A Fatal error occurs because the exception is thrown. I didn't see your T_STRING error. Check to make sure you're working with the latest code.

Dan

Share this Question
Share on Google+
4 Replies


dlite922
Expert 100+
P: 1,584
Are you sure you're using php 5.1 or above?

call phpinfo(); at the top of your file to check.

dan
Jan 30 '12 #2

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

dlite922
Expert 100+
P: 1,584
I copy and pasted your code. It works as expected. A Fatal error occurs because the exception is thrown. I didn't see your T_STRING error. Check to make sure you're working with the latest code.

Dan
Jan 31 '12 #4

P: 6
@dlite922
You are correct. my editor has a built in PHP checker that is not up-to-date.
Your insisting that the code is correct forced me to sharpen my pencil abit more and get to the bottom of this

Thank you for your effort.
Jan 31 '12 #5

Post your reply

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