• PHP Help PHP Coding
  • [RESOLVED] Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION

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 object is being called from another file:

Code in the main file:

include_once ('securimage.php'); 
$secureimage = new Securimage();  

The file is there, named exactly that.

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

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.

I know that I'm in the right file because if I comment out that line, then the same error occurs on the next constant:

const SI_IMAGE_PNG  = 2;  

I'm running PHP version 5.2.17.

Why would I be getting this error?

    As far as it goes, what you've posted has no parse errors.

      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.

        Many hosting companies provide both PHP 4.x and PHP 5.x by processing one as an Apache SAPI module and one as CGI, differentiating them by file name suffix. However, once you the web server launches the initially called file based on that file name suffix, from that point on, any files it includes will be running under the same version, as include()/require() calls are not being processed by the web server, they're just being read into and processed by the calling script at that point.

        PS: In any case, unless you specifically need PHP 4.x to run some antiquated script that won't run in PHP 5.x (and have neither the time nor inclination to fix it), I'd have everything run as PHP 5. 🙂

          Yeah, that was part of my request to them. To have it all running with PHP 5. No reason for me not to have it do that.

          Thanks. 😉

            Write a Reply...