LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-04-2011, 07:15 PM   #1
lpallard
Senior Member
 
Registered: Nov 2008
Posts: 1,045

Rep: Reputation: Disabled
Php Parse error (unexpected T_String)


Hi!

Part of the problems I am trying to solve with my Horde installation, I have to insert a debug statement in a specific PHP file of the Horde framework. The instructions were given to me in the bug ticket by a project admin and his instructions were very clear and consist in inserting

Code:
Horde::debug($fetch_res);
just before line 2089 in the file to debug. The problem is that when I insert this line, I get a blank page and the apache error log says:

Code:
[Tue Oct 04 20:04:09 2011] [error] [client 192.XXX.XXX.XXX] PHP Parse error:  syntax error, unexpected T_STRING in /usr/lib/php/Horde/Imap/Client/Socket.php on line 2089, referer: http://192.XXX.XXX.XXX/horde4/login.php
If I remove the "Horde::debug($fetch_res);" line the application works as expected. According to the people at Horde, my PHP install is broken. How do I find the problem with my PHP setup? Is it only just a syntax error? What is wrong? I've searched for days without finding anything. The debug statement of the horde application seems very proprietary, that is, I couldn't find anything that even looks similar so I cant compare with other cases and figure out myself.

An excerpt of the code I am trying to modify (line 2089 as referred to in the Apache error log is in bold below):
As is (working):
Code:
                case Horde_Imap_Client::SORT_TO:
                    if ($val == Horde_Imap_Client::SORT_CC) {
                        $field = 'cc';
                    } elseif ($val == Horde_Imap_Client::SORT_FROM) {
                        $field = 'from';
                    } else {
                        $field = 'to';
                    }

                    foreach ($slice as $num) {
                        $env = $fetch_res[$num]->getEnvelope();
                        $sorted[$num] = empty($env->$field)
                         ? null
                         : $env->$field[0]['personal'];
                    }
                    asort($sorted, SORT_LOCALE_STRING);
                    break;
Modified (with debug statement, not working):
Code:
                case Horde_Imap_Client::SORT_TO:
                    if ($val == Horde_Imap_Client::SORT_CC) {
                        $field = 'cc';
                    } elseif ($val == Horde_Imap_Client::SORT_FROM) {
                        $field = 'from';
                    } else {
                        $field = 'to';
                    }

                    foreach ($slice as $num) {
                        $env = $fetch_res[$num]->getEnvelope();
                        $sorted[$num] = empty($env->$field)
                            ? null
                           Horde::debug($fetch_res);
                         : $env->$field[0]['personal'];
                    }
                    asort($sorted, SORT_LOCALE_STRING);
                    break;
Anybody can help?

EDIT: I forgot to mention: PHP 5.3.3 running on Slackware 13.1

Last edited by lpallard; 10-04-2011 at 07:19 PM.
 
Old 10-04-2011, 09:08 PM   #2
pdq2
LQ Newbie
 
Registered: Sep 2011
Distribution: Ubuntu 11.10
Posts: 2

Rep: Reputation: Disabled
This is actually one line of code (the ; symbol indicates the end of each line of code) and you cannot insert that line within it:
Code:
                        $sorted[$num] = empty($env->$field)
                         ? null
                         : $env->$field[0]['personal'];
ie:
Code:
$sorted[$num] = empty($env->$field) ? null : $env->$field[0]['personal'];
So if adding new lines into your file it must go above or below that line.

=]
 
Old 10-05-2011, 04:14 AM   #3
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
You could rewrite the statement
Code:
$sorted[$num] = empty($env->$field)
                            ? null
                           Horde::debug($fetch_res);
                         : $env->$field[0]['personal'];
Code:
if( empty($env->$field) ) {
    $sorted[$num] = null;
    Horde::debug($fetch_res);
} else {
    $sorted[$num] = $env->$field[0]['personal']
}
I don't think you can just replace the null expression with a statement block like {null; Horde::debug($fetch_res);}
http://php.net/manual/en/language.op...arison.ternary
 
Old 10-05-2011, 06:17 AM   #4
lpallard
Senior Member
 
Registered: Nov 2008
Posts: 1,045

Original Poster
Rep: Reputation: Disabled
Bingo! I did not know that the semicolon was a command ending and that commands in php could split on several lines like this

Code:
     $sorted[$num] = empty($env->$field)
                         ? null
                         : $env->$field[0]['personal'];
Will know better next time!

Thanks to both of you!
 
Old 10-09-2011, 03:53 PM   #5
lpallard
Senior Member
 
Registered: Nov 2008
Posts: 1,045

Original Poster
Rep: Reputation: Disabled
Quickly back to the topic about PHP. I am having a problem which I cant troubleshoot on my own, not having PHP experience... I tried to google, but the issue seems too specific and potential solutions did not work so far..

Basically, I am having 2 different errors, one is FATAL the other one is a WARNING. Both seems to be based on the same problem:

Code:
[Sun Oct 09 14:54:30 2011] [error] [client 192.xxx.xxx.xxx] PHP Warning:  require_once(Horde/Autoloader/Default.php) [<a href='function.require-once'>function.require-
once</a>]: failed to open stream: No such file or directory in /var/www/htdocs/horde4/lib/core.php on line 46
Code:
[Sun Oct 09 14:54:30 2011] [error] [client 192.xxx.xxx.xxx] PHP Fatal error:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required 
'Horde/Autoloader/Default.php' (include_path='/var/www/htdocs/horde4/lib:.:/usr/lib/php') in /var/www/htdocs/horde4/lib/core.php on line 46
But Autoloader.php is indeed in /usr/lib/php/Horde/Autoloader/ and is owned by Apache:Apache.

Any clues why PHP cant "find" the Autoloader.php file?

A quick google search pointed out to 4 causes:

Quote:
The file is really not there, something went wrong with the installation - reinstall.
The file is there, I checked.

Quote:
The file is there but the web server does not have the right to open it - check permissions.
ls -l
Code:
-rw-r--r-- 1 apache apache 943 2011-09-24 13:31 Default.php
Quote:
There is a .htaccess file somewhere in the directory hierarchy that denies access even to you.
No. I checked and there is no .htaccess file in the directory hierarchy. Plus, this problem started after I last upgraded horde so my apache config is not to blame...

Quote:
There is something wrong with the include path of the PHP interpreter.
According to the errors in Apache logs, the include path includes /usr/lib/php which in turns include Horde/Autoloader/Default.php so the file is in the search path...

I must admit I am not sure if its a PHP problem, a Horde problem, or Apache problem... Any help will be much appreciated!

Last edited by lpallard; 10-09-2011 at 04:00 PM.
 
Old 10-09-2011, 11:19 PM   #6
lpallard
Senior Member
 
Registered: Nov 2008
Posts: 1,045

Original Poster
Rep: Reputation: Disabled
Well I solved it.. Was some kind of directives in my apache config file that caused problems... Removed the directives and back in business!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: syntax error, unexpected T_STRING in /home/dodonet2/public_html/includes bestbuddy Linux - Newbie 8 01-10-2010 08:31 PM
PHP parse error: unexpected { li0n Programming 4 02-24-2009 05:12 AM
PHP Error Parse error: parse error, unexpected $ in /home/content/S/k/i/SkinCare4U/h CowanServices Programming 2 12-09-2008 08:26 PM
need help with "Parse error: parse error, unexpected T_STRING" coffee245 Programming 2 01-29-2007 11:53 AM
PHP parse error unexpected '>' ldp Programming 2 03-04-2005 02:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration