The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Php Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNC
Discuss Php Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNC in the PHP Development forum on Dev Shed. Php Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNC PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 23rd, 2013, 06:05 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 99
 
Time spent in forums: 21 h 59 m 39 sec
Reputation Power: 1
|
|
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:
Quote: | 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:
b.t.w. I'm running PHP version 5.2.17.
Why would I be getting this error?
|

February 23rd, 2013, 06:37 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
What's the rest of the code?
|

February 23rd, 2013, 06:59 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 99
 
Time spent in forums: 21 h 59 m 39 sec
Reputation Power: 1
|
|
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.
|

February 23rd, 2013, 08:19 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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.
|

February 24th, 2013, 12:34 AM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 99
 
Time spent in forums: 21 h 59 m 39 sec
Reputation Power: 1
|
|
Quote: | 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:
|

February 24th, 2013, 12:45 AM
|
 |
Lost in code
|
|
|
|
You would only receive that error message in this context if you were not actually running PHP 5.
Add:
immediately before your require statement and determining what value it outputs. I would be very surprised if it's actually 5.2.17.
|

February 24th, 2013, 01:07 AM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 99
 
Time spent in forums: 21 h 59 m 39 sec
Reputation Power: 1
|
|
Quote: | Originally Posted by E-Oreo You would only receive that error message in this context if you were not actually running PHP 5.
Add:
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):
I get PHP version 5.2.17.
And using:
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?
|

February 24th, 2013, 06:26 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
There's some difference. Maybe the way the run is running, maybe the file extension, maybe where the file is located... Something is different.
|

February 25th, 2013, 08:27 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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.
|

February 25th, 2013, 06:40 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 99
 
Time spent in forums: 21 h 59 m 39 sec
Reputation Power: 1
|
|
Quote: | 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.
|

February 25th, 2013, 06:44 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 99
 
Time spent in forums: 21 h 59 m 39 sec
Reputation Power: 1
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|