treeleaf20 Posted October 19, 2011 Share Posted October 19, 2011 All, I'm getting the following error when I work with a class: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /webspace/httpdocs/offers/form_key.php on line 5 The complete code for this is class is: <?php class Form_Key { protected $oldKey; public function __construct() { // Ensure we have an available session if ( NULL == session_id() ) { session_start(); } // Grab our former key for validation if ( isset( $_SESSION['form_key'] ) ) { $this->oldKey = $_SESSION['form_key']; } // Assign the new key $_SESSION['form_key'] = md5( uniqid( mt_rand(), TRUE ) ); } public function isValid() { return 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['form_key'] ) && '' != trim( $_POST['form_key'] ) && '' != trim( $this->oldKey ) && $_POST['form_key'] === $this->oldKey; } public function getKey() { return $_SESSION['form_key']; } public function getOldKey() { return $this->oldKey; } public function render() { return '<input type="hidden" name="form_key" value="' . $_SESSION['form_key'] . '" />'; } public function __toString() { return $this->render(); } } ?> The line that is giving the issue is this line: protected $oldKey; Is it ok just to remove this line?? If I comment it out it gives me the same message but for line 7, which is this one: public function __construct() Anyone have any ideas? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/249420-class-is-giving-me-an-error/ Share on other sites More sharing options...
Zane Posted October 19, 2011 Share Posted October 19, 2011 You must be running PHP4. take away the protected/private parts. In other words.. protected $oldKey becomes var $oldKey or simply... $oldKey = null; Quote Link to comment https://forums.phpfreaks.com/topic/249420-class-is-giving-me-an-error/#findComment-1280652 Share on other sites More sharing options...
treeleaf20 Posted October 19, 2011 Author Share Posted October 19, 2011 If I make it: $oldKey = null; I get the following error: Parse error: syntax error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /usr/local/pem/vhosts/243668/webspace/httpdocs/offers/form_key.php on line 5 If I make it: var $oldKey; I get the following error: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /usr/local/pem/vhosts/243668/webspace/httpdocs/offers/form_key.php on line 7 Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/249420-class-is-giving-me-an-error/#findComment-1280655 Share on other sites More sharing options...
Zane Posted October 19, 2011 Share Posted October 19, 2011 Well apparently var $oldkey works then Line 7 is bad because it begins with public. Take out the public part and it'll go to line... something higher than 7 which would be the other "public" function Take note that in PHP4, public, private, protected and static didn't exist. The quick and dirty solution is to take all the private/protected/public parts out. The ultimate fix would be to upgrade to PHP5, in which OOP is implemented correctly.. or traditionally rather. Quote Link to comment https://forums.phpfreaks.com/topic/249420-class-is-giving-me-an-error/#findComment-1280657 Share on other sites More sharing options...
treeleaf20 Posted October 19, 2011 Author Share Posted October 19, 2011 That did the trick, I'm using domain.com. How can I tell what version of PHP they are using? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/249420-class-is-giving-me-an-error/#findComment-1280658 Share on other sites More sharing options...
xyph Posted October 19, 2011 Share Posted October 19, 2011 take away the... private parts. kekekeke That did the trick, I'm using domain.com. How can I tell what version of PHP they are using? Thanks! phpversion Quote Link to comment https://forums.phpfreaks.com/topic/249420-class-is-giving-me-an-error/#findComment-1280661 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.