Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/249420-class-is-giving-me-an-error/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.