Compdigitec Labs

« | Home | »

Stopping syntax error, unexpected ‘;’, expecting T_FUNCTION

By admin | July 19, 2008

If you’ve ever been stumped by “Parse error: syntax error, unexpected ‘;’, expecting T_FUNCTION”, you will know that this is a very difficult bug to track. Fortunately, we have found the error for you.

This error message is very misleading, because your actual problem is that you have an extra semi-colon at the end of your functions, like the one below (see line 12):

<?php
// Demo Syntax Error Example
// Public domain

class Demo {
     var $a;
     var $b;

     function problem_here() {
          $this->a = 'Hello World!';
     }; # <-- That one
};
?>

Now, the above code looks good, but when you try to run it it PHP spits out the following parse error:

Parse error: syntax error, unexpected ‘;’, expecting T_FUNCTION in *.php on line *

So, to fix it, simply remove the offending semi-colon at the end of your functions. Hope this helped anyone who got stuck with this misleading PHP error.

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!

Topics: PHP | 26 Comments »

26 Responses to “Stopping syntax error, unexpected ‘;’, expecting T_FUNCTION”

  1. egodi Says:
    August 27th, 2009 at 13:48

    mine is
    PHP Parse error: syntax error, unexpected $end, expecting T_FUNCTION in C:\\\test\file.php on line 86

  2. Gregor Says:
    September 26th, 2009 at 04:15

    Parse error: syntax error, unexpected ‘;’, expecting T_FUNCTION on lin 519.

    The line 519 is just ?>

    what can I do?

  3. admin Says:
    September 27th, 2009 at 15:48

    @Gregor:

    Did you by accident put in an extra semi-colon somewhere in your code before the “?>”?

  4. Gregor Says:
    September 28th, 2009 at 05:22

    I checked the whole php file, no ; before ?>. Is it possible to send you the (searchajax).php file?

    This are some of the lines of the code:

    ?>

    <input value=" ” class=”form2_submit” type=”submit”>

    (<- line 519)

  5. Asdf Says:
    November 11th, 2009 at 14:01

    Someone said
    “Parse error: syntax error, unexpected ‘;’, expecting T_FUNCTION on lin 519.
    The line 519 is just ?>”

    The same error to me. It was a } missing at the end, just before ?>. It was something like..

    It was a deletion error.

  6. aeou Says:
    December 23rd, 2009 at 17:44

    the following snippet will output the same message (only when inside a class method, not in or out of a procedural function)

    class Foo {
    public function foo() {
    if ($a) {
    echo ‘foo’;
    if ($b) {
    echo ‘bar’;
    }
    }
    }

  7. grobemo Says:
    April 6th, 2010 at 22:59

    Thanks! This helped me fix this otherwise puzzling bug.

    If you’re getting the “unexpected $end, expecting T_FUNCTION” variation (as egodi does above), it may be because you’ve forgotten to close the class declaration. Try adding a final } after your last method declaration (i.e., after your last function).

  8. Michael Boggess Says:
    April 20th, 2010 at 22:57

    I had this error buy it ended up I did not close an if block mid way through the class. Watch out for that stuff.

  9. Alex Says:
    July 2nd, 2010 at 10:12

    Thanks Asdf.
    Just put a { to the end.

  10. KGF2009 Says:
    July 12th, 2010 at 01:33

    Though I’m sure this is rare, but it could happen if you declare a lot of functions in your class, this error will also be thrown if the class itself is not closed.

  11. David Cobb Says:
    October 26th, 2010 at 16:50

    I agree with the post above and I will find more information from google.

  12. the_smiley Says:
    January 21st, 2011 at 07:14

    i had exactly the same problem as the guy with error coming from the line with the ?> tag, though it was an if statement who’s closing bracket i had erroniously commented out

  13. Anne Hedonia Says:
    March 20th, 2011 at 01:11

    I LOVE YOU PEOPLE! Added an extra { to the end of my code and it was all fixed. ::MWAH!::

  14. Anne Hedonia Says:
    March 20th, 2011 at 01:11

    (Actually, I meant an extra }. Sorry, I’ve been at this too long.

  15. nick Says:
    May 8th, 2011 at 21:43

    Parse error: syntax error, unexpected ‘}’ that shut me down. I can not access the phpbb admin. Anyone see a problem

    {META}
    {SITENAME} • <!– IF S_IN_MCP –>{L_MCP} • <!– ELSEIF S_IN_UCP –>{L_UCP} • <!– ENDIF –>{PAGE_TITLE}






    // <![CDATA[

    if ({S_NEW_PM})
    {
    popup(‘{UA_POPUP_PM}’, 400, 225, ‘_phpbbprivmsg’);
    }

    function popup(url, width, height, name)
    {
    if (!name)
    {
    name = ‘_popup’;
    }

    window.open(url.replace(/&/g, ‘&’), name, ‘height=’ + height + ‘,resizable=yes,scrollbars=yes,width=’ + width);
    return false;
    }

    function jumpto()
    {
    var page = prompt(‘{LA_JUMP_PAGE}:’, ‘{ON_PAGE}’);
    var per_page = ‘{PER_PAGE}’;
    var base_url = ‘{A_BASE_URL}’;

    if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0)
    {
    if (base_url.indexOf(‘?’) == -1)
    {
    document.location.href = base_url + ‘?start=’ + ((page – 1) * per_page);
    }
    else
    {
    document.location.href = base_url.replace(/&/g, ‘&’) + ‘&start=’ + ((page – 1) * per_page);
    }
    }
    }

    /**
    * Find a member
    */
    function find_username(url)
    {
    popup(url, 760, 570, ‘_usersearch’);
    return false;
    }

    /**
    * Mark/unmark checklist
    * id = ID of parent container, name = name prefix, state = state [true/false]
    */
    function marklist(id, name, state)
    {
    var parent = document.getElementById(id);
    if (!parent)
    {
    eval(‘parent = document.’ + id);
    }

    if (!parent)
    {
    return;
    }

    var rb = parent.getElementsByTagName(‘input’);

    for (var r = 0; r < rb.length; r++)
    {
    if (rb[r].name.substr(0, name.length) == name)
    {
    rb[r].checked = state;
    }
    }
    }

    /**
    * Play quicktime file by determining it’s width/height
    * from the displayed rectangle area
    *
    * Only defined if there is a file block present.
    */
    function play_qt_file(obj)
    {
    var rectangle = obj.GetRectangle();

    if (rectangle)
    {
    rectangle = rectangle.split(‘,’)
    var x1 = parseInt(rectangle[0]);
    var x2 = parseInt(rectangle[2]);
    var y1 = parseInt(rectangle[1]);
    var y2 = parseInt(rectangle[3]);

    var width = (x1 < 0) ? (x1 * -1) + x2 : x2 – x1;
    var height = (y1 < 0) ? (y1 * -1) + y2 : y2 – y1;
    }
    else
    {
    var width = 200;
    var height = 0;
    }

    obj.width = width;
    obj.height = height + 16;

    obj.SetControllerVisible(true);

    obj.Play();
    }

    // ]]>


    {L_LOGIN_LOGOUT}    {L_RESTORE_PERMISSIONS}  {L_BOARD_DISABLED}   {PRIVATE_MESSAGE_INFO}, {PRIVATE_MESSAGE_INFO_UNREAD}   {L_REGISTER}
    {L_FAQ}    {L_SEARCH}    {L_MEMBERLIST}    {L_PROFILE}

    {LAST_VISIT_DATE}
    {CURRENT_TIME}



    {L_SEARCH_UNANSWERED} | {L_SEARCH_ACTIVE_TOPICS}{L_SEARCH_UNREAD} | {L_SEARCH_NEW} | {L_SEARCH_SELF}

  16. Joel Says:
    June 10th, 2012 at 00:17

    Sometimes you’re just missing a “}”.

  17. Jim Says:
    June 19th, 2012 at 23:59

    This may be the problem, but what line would it complain about? Would it complain about the correct line, the one before, the one after, etc…?

  18. phpdeveloper Says:
    October 25th, 2013 at 03:56

    PHP Parse error: syntax error, unexpected ‘;’, expecting T_FUNCTION in /home/nakul/locl.cms.com/connectionManager.php on line 35

    server = $server;
    $this->username = $username;
    $this->password = $password;
    $this->db_name = $db_name;
    $this->connect();
    }
    function connect() {
    mysqli_connect($this->server, $this->username, $this->password) or die(mysql_error());
    mysqli_select_db($this->db_name) or die(mysql_error());
    }
    ?>

  19. Deepak Says:
    January 19th, 2015 at 02:58

    ERROR :-
    Parse error: syntax error, unexpected ‘protected’ (T_PROTECTED) in /opt/lampp/htdocs/custom_module/admin/controller/module/helloworld.php on line 124

    CODE :- language->load(‘module/helloworld’); // Loading the language file of helloworld

    $this->document->setTitle($this->language->get(‘heading_title’)); // Set the title of the page to the heading title in the Language file i.e., Hello World

    $this->load->model(‘setting/setting’); // Load the Setting Model (All of the OpenCart Module & General Settings are saved using this Model )

    if (($this->request->server[‘REQUEST_METHOD’] == ‘POST’) && $this->validate()) { // Start If: Validates and check if data is coming by save (POST) method
    $this->model_setting_setting->editSetting(‘helloworld’, $this->request->post); // Parse all the coming data to Setting Model to save it in database.

    $this->session->data[‘success’] = $this->language->get(‘text_success’); // To display the success text on data save

    $this->redirect($this->url->link(‘extension/module’, ‘token=’ . $this->session->data[‘token’], ‘SSL’)); // Redirect to the Module Listing
    } // End If

    /*Assign the language data for parsing it to view*/
    $this->data[‘heading_title’] = $this->language->get(‘heading_title’);

    $this->data[‘text_enabled’] = $this->language->get(‘text_enabled’);
    $this->data[‘text_disabled’] = $this->language->get(‘text_disabled’);
    $this->data[‘text_content_top’] = $this->language->get(‘text_content_top’);
    $this->data[‘text_content_bottom’] = $this->language->get(‘text_content_bottom’);
    $this->data[‘text_column_left’] = $this->language->get(‘text_column_left’);
    $this->data[‘text_column_right’] = $this->language->get(‘text_column_right’);

    $this->data[‘entry_code’] = $this->language->get(‘entry_code’);
    $this->data[‘entry_layout’] = $this->language->get(‘entry_layout’);
    $this->data[‘entry_position’] = $this->language->get(‘entry_position’);
    $this->data[‘entry_status’] = $this->language->get(‘entry_status’);
    $this->data[‘entry_sort_order’] = $this->language->get(‘entry_sort_order’);

    $this->data[‘button_save’] = $this->language->get(‘button_save’);
    $this->data[‘button_cancel’] = $this->language->get(‘button_cancel’);
    $this->data[‘button_add_module’] = $this->language->get(‘button_add_module’);
    $this->data[‘button_remove’] = $this->language->get(‘button_remove’);

    /*This Block returns the warning if any*/
    if (isset($this->error[‘warning’])) {
    $this->data[‘error_warning’] = $this->error[‘warning’];
    } else {
    $this->data[‘error_warning’] = ”;
    }
    /*End Block*/

    /*This Block returns the error code if any*/
    if (isset($this->error[‘code’])) {
    $this->data[‘error_code’] = $this->error[‘code’];
    } else {
    $this->data[‘error_code’] = ”;
    }
    /*End Block*/

    /* Making of Breadcrumbs to be displayed on site*/
    $this->data[‘breadcrumbs’] = array();

    $this->data[‘breadcrumbs’][] = array(
    ‘text’ => $this->language->get(‘text_home’),
    ‘href’ => $this->url->link(‘common/home’, ‘token=’ . $this->session->data[‘token’], ‘SSL’),
    ‘separator’ => false
    );

    $this->data[‘breadcrumbs’][] = array(
    ‘text’ => $this->language->get(‘text_module’),
    ‘href’ => $this->url->link(‘extension/module’, ‘token=’ . $this->session->data[‘token’], ‘SSL’),
    ‘separator’ => ‘ :: ‘
    );

    $this->data[‘breadcrumbs’][] = array(
    ‘text’ => $this->language->get(‘heading_title’),
    ‘href’ => $this->url->link(‘module/helloworld’, ‘token=’ . $this->session->data[‘token’], ‘SSL’),
    ‘separator’ => ‘ :: ‘
    );

    /* End Breadcrumb Block*/

    $this->data[‘action’] = $this->url->link(‘module/helloworld’, ‘token=’ . $this->session->data[‘token’], ‘SSL’); // URL to be directed when the save button is pressed

    $this->data[‘cancel’] = $this->url->link(‘extension/module’, ‘token=’ . $this->session->data[‘token’], ‘SSL’); // URL to be redirected when cancel button is pressed

    /* This block checks, if the hello world text field is set it parses it to view otherwise get the default hello world text field from the database and parse it*/

    if (isset($this->request->post[‘helloworld_text_field’])) {
    $this->data[‘helloworld_text_field’] = $this->request->post[‘helloworld_text_field’];
    } else {
    $this->data[‘helloworld_text_field’] = $this->config->get(‘helloworld_text_field’);
    }
    /* End Block*/

    $this->data[‘modules’] = array();

    /* This block parses the Module Settings such as Layout, Position,Status & Order Status to the view*/
    if (isset($this->request->post[‘helloworld_module’])) {
    $this->data[‘modules’] = $this->request->post[‘helloworld_module’];
    } elseif ($this->config->get(‘helloworld_module’)) {
    $this->data[‘modules’] = $this->config->get(‘helloworld_module’);
    }
    /* End Block*/

    $this->load->model(‘design/layout’); // Loading the Design Layout Models

    $this->data[‘layouts’] = $this->model_design_layout->getLayouts(); // Getting all the Layouts available on system

    $this->template = ‘module/helloworld.tpl’; // Loading the helloworld.tpl template
    $this->children = array(
    ‘common/header’,
    ‘common/footer’
    ); // Adding children to our default template i.e., helloworld.tpl

    $this->response->setOutput($this->render()); // Rendering the Output
    }
    }

    /* Function that validates the data when Save Button is pressed */
    protected function validate() {

    /* Block to check the user permission to manipulate the module*/
    if (!$this->user->hasPermission(‘modify’, ‘module/helloworld’)) {
    $this->error[‘warning’] = $this->language->get(‘error_permission’);
    }
    /* End Block*/

    /* Block to check if the helloworld_text_field is properly set to save into database, otherwise the error is returned*/
    if (!$this->request->post[‘helloworld_text_field’]) {
    $this->error[‘code’] = $this->language->get(‘error_code’);
    }
    /* End Block*/

    /*Block returns true if no error is found, else false if any error detected*/
    if (!$this->error) {
    return true;
    } else {
    return false;
    }
    /* End Block*/
    }
    /* End Validation Function*/

    Note :- I have already trying this—–

  20. antalya web tasarım Says:
    October 8th, 2016 at 04:38

    thanks for nice code i fixed it

  21. :: Says:
    November 5th, 2024 at 04:53

    … [Trackback]

    […] Here you will find 49139 more Information on that Topic: compdigitec.com/labs/2008/07/19/stopping-syntax-error-expecting-t_function/ […]

  22. สล็อต ราเมง ทางเข้าเว็บสล็อตเปิดใหม่ Says:
    November 9th, 2024 at 22:05

    … [Trackback]

    […] Find More here on that Topic: compdigitec.com/labs/2008/07/19/stopping-syntax-error-expecting-t_function/ […]

  23. zbet911 Says:
    November 12th, 2024 at 18:20

    … [Trackback]

    […] Information on that Topic: compdigitec.com/labs/2008/07/19/stopping-syntax-error-expecting-t_function/ […]

  24. sci/sci news/news sci/ science diyala Says:
    November 13th, 2024 at 11:07

    … [Trackback]

    […] Info to that Topic: compdigitec.com/labs/2008/07/19/stopping-syntax-error-expecting-t_function/ […]

  25. ทางเข้าpg Says:
    November 22nd, 2024 at 06:26

    … [Trackback]

    […] Find More here to that Topic: compdigitec.com/labs/2008/07/19/stopping-syntax-error-expecting-t_function/ […]

  26. SHOPEE สล็อต Says:
    December 16th, 2024 at 22:38

    … [Trackback]

    […] Here you will find 19680 additional Info to that Topic: compdigitec.com/labs/2008/07/19/stopping-syntax-error-expecting-t_function/ […]

Comments