unkwntech Posted November 26, 2008 Share Posted November 26, 2008 I have a block of code that looks like this: function sendResponseCode($code) { error_reporting(0); switch ($code) { ...SNIP... default: throw new Exception('Response Code Not Implemented', '1'); //<-- LINE 11 break; } die(); } ...SNIP... if(!DEFINED(constName)) { try { sendResponseCode(404); } catch(Exception $e) { echo $e->getMessage() . ' on line: ' . $e->getLine() . ' of file ' . $e->getFile(); } } when I run it I am getting the following: Parse error: parse error, unexpected T_NEW in ...SNIP... on line 11 Link to comment https://forums.phpfreaks.com/topic/134334-solved-throw-new-exception-trouble/ Share on other sites More sharing options...
genericnumber1 Posted November 26, 2008 Share Posted November 26, 2008 What version of php are you using? edit: oh, and what is the case right above "default" if you're using php 5. Link to comment https://forums.phpfreaks.com/topic/134334-solved-throw-new-exception-trouble/#findComment-699350 Share on other sites More sharing options...
unkwntech Posted November 26, 2008 Author Share Posted November 26, 2008 Using PHP versions 4&5, and I sniped all the case's as there are quite a few, this error is coming from 5. Link to comment https://forums.phpfreaks.com/topic/134334-solved-throw-new-exception-trouble/#findComment-699356 Share on other sites More sharing options...
genericnumber1 Posted November 26, 2008 Share Posted November 26, 2008 only php 5 has exceptions. If it's on a php 5 server causing an issue, can you show us the case right above the default one? There's no syntax problem in the ones you're showing me. Link to comment https://forums.phpfreaks.com/topic/134334-solved-throw-new-exception-trouble/#findComment-699359 Share on other sites More sharing options...
unkwntech Posted November 26, 2008 Author Share Posted November 26, 2008 function sendResponseCode($code) { error_reporting(0); switch ($code) { ...SNIP... case 404: header('HTTP/1.1 404 Not Found\r\n'); break; default: throw new Exception('Response Code Not Implemented', '1'); break; } die(); } ...SNIP... if(!DEFINED(constName)) { try { sendResponseCode(404); } catch(Exception $e) { echo $e->getMessage() . ' on line: ' . $e->getLine() . ' of file ' . $e->getFile(); } } Link to comment https://forums.phpfreaks.com/topic/134334-solved-throw-new-exception-trouble/#findComment-699360 Share on other sites More sharing options...
genericnumber1 Posted November 26, 2008 Share Posted November 26, 2008 Well.. there is nothing syntactically wrong with your code, and the error message you are getting is consistent with using throw new on php 4. I'd check the php configuration. Link to comment https://forums.phpfreaks.com/topic/134334-solved-throw-new-exception-trouble/#findComment-699362 Share on other sites More sharing options...
unkwntech Posted November 26, 2008 Author Share Posted November 26, 2008 I'm gonna' beat my head against the desk for a while now.... the server I was testing on hadn't been updated for whatever reason to PHP5 so it was still running 4.4.0. So I'll change the question is there a way to accomplish this in 4? Note To Self: Check the versions don't rely on what 'they' tell you. Link to comment https://forums.phpfreaks.com/topic/134334-solved-throw-new-exception-trouble/#findComment-699363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.