#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    150
    Rep Power
    3

    Question Php Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNC


    Hi all,

    Getting this error while trying to create a constant inside an object:

    php Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'
    The line it's complaining about is this, which is inside a class:

    PHP Code:
    const SI_IMAGE_JPEG 1
    b.t.w. I'm running PHP version 5.2.17.

    Why would I be getting this error?
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    150
    Rep Power
    3
    the object is being called from another file:

    PHP Code:
    include_once ('securimage.php');
    $secureimage = new Securimage(); 
    The file is there, named exactly that.

    The Securimage() object, in the securimage.php is:

    PHP Code:
    class Securimage
    {
        
    // All of the public variables below are securimage options
        // They can be passed as an array to the Securimage constructor, set below,
        // or set from securimage_show.php and securimage_play.php

        /**
         * Renders captcha as a JPEG image
         * @var int
         */
        
    const SI_IMAGE_JPEG 1; <----
        
    /**
         * Renders captcha as a PNG image (default)
         * @var int
         */
        
    const SI_IMAGE_PNG  2
    and continues.

    The line with the arrow is the line the error is occuring on according to php.
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    That code works for me. Are you sure you're in the right file?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    150
    Rep Power
    3
    Originally Posted by ManiacDan
    That code works for me. Are you sure you're in the right file?
    Yeah, because if I comment out that line, then the error occurs on the next constant:

    PHP Code:
    const SI_IMAGE_PNG  2
  10. #6
  11. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    You would only receive that error message in this context if you were not actually running PHP 5.

    Add:
    PHP Code:
    die(phpversion()); 
    immediately before your require statement and determining what value it outputs. I would be very surprised if it's actually 5.2.17.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    150
    Rep Power
    3
    Originally Posted by E-Oreo
    You would only receive that error message in this context if you were not actually running PHP 5.

    Add:
    PHP Code:
    die(phpversion()); 
    immediately before your require statement and determining what value it outputs. I would be very surprised if it's actually 5.2.17.
    Well isn't that interesting.

    When using (at the top of the page):

    PHP Code:
    echo phpinfo(); 
    I get PHP version 5.2.17.

    And using:
    PHP Code:
    die(phpversion()); 
    I get 4.4.9

    Why the difference? Perhaps because I'm on a shared server? How does that work? Some on the server have 5.2.17, and my site doesn't?

    It makes sense now why the OO PHP doesn't work if I'm really running 4.4.9 and not 5.2.17. But still, two different answers on the same page?
  14. #8
  15. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    There's some difference. Maybe the way the run is running, maybe the file extension, maybe where the file is located... Something is different.
  16. #9
  17. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Yeah...it might be a good idea to uninstall/reinstall PHP.

    Are you really saying that if you put phpinfo() at the top of the page, you get 5+, and if you put phpversion() at the bottom of the page, you get 4? You're accessing the page in the same way?
    Last edited by ManiacDan; February 25th, 2013 at 08:39 AM.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    150
    Rep Power
    3
    Originally Posted by ManiacDan
    Yeah...it might be a good idea to uninstall/reinstall PHP.

    Are you really saying that if you put phpinfo() at the top of the page, you get 5+, and if you put phpversion() at the bottom of the page, you get 4? You're accessing the page in the same way?
    Yeah.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    150
    Rep Power
    3
    I finally figured out what was going on.

    If the page calling the OO PHP was a .html page, phpversion() shows 4.4.9.
    If the page calling the OO PHP was a .php page, phpversion() shows 5.2.17.

    And, either page extension type would show version 5.2.17 with phpinfo();

    Even though the page (either the .html or the .php version) were accessed in the same way and they had identical code...only the .php extension page would get phpversion() to show the 5.2.17 version whereas the .html page would give the 4.4.9 version.

    Why that's the case, I don't know yet (probably server configuration as to how .html pages are rendered with the php engine), but I got it working now by simply changing the page extension from .html to .php.

    The server host company is making changes to allow .html pages to behave the same with this regards.
    Last edited by we5inelgr; February 25th, 2013 at 06:49 PM.

IMN logo majestic logo threadwatch logo seochat tools logo