Solved

Parse Error For Double Quotes in PHP5 and Apache 2.2 on Windows 7

Posted on 2011-09-14
18
693 Views
Last Modified: 2012-05-12
I have installed Apache 2.2.20 and PHP 5.3.8 on a Windows 7 system. I have an include file which has lines like the following :

require($_PHPLIB["libdir"] . "db_mysql.inc"); /* Change this ... */

This generates a parse error:

unexpected "", expecting T_STRING or T_VARIABLE or T_NUM_STRING in ...


Note that libdir is defined above this line, as follows, and does not generaqte a parse error:

$_PHPOLIB["libdir'] = "c:\phplib";

If I rewite  $_PHPLIB["libdir"] as $_PHPLIB['libdir'] in the require() statement, it fixes the error noted above, but I get a different parse error.

Rather than present each of these, the bottom line is I had to rewrite the code line as:

require($_PHPLIB[libdir'] . 'db_mysql.inc');  /* Change this ... */

to get rid of all the parse errors related to that line.

Note, I have PHP5 and Apache 2.2 installed on a Linux server as well, and the identical include file is there with all the double quotes as above. No parse errors.

Why is PHP behaving differently under Windows than it does under Linux, with respect to these double quotes inside the require() statement, but not outside of it?

0
Comment
Question by:MaglinFurniture
  • 8
  • 5
  • 5
18 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36538741
I think we might need to see the code, copied and pasted into the code snippet.  This line (copied from above) will almost certainly cause a parse error.  The quotes are unbalanced.
$_PHPOLIB["libdir'] = "c:\phplib";

Open in new window

0
 

Author Comment

by:MaglinFurniture
ID: 36538887
Here is the file, as it is installed on our live website, which runs under Linux 5.something and Apache 2.2, PHP 5.3:

<?php
/*
 * Session Management for PHP3
 *
 * Copyright (c) 1998-2000 NetUSE AG
 *                    Boris Erdmann, Kristian Koehntopp
 *
 * $Id: prepend.php3,v 1.4 2001/07/14 20:24:55 kk Exp $
 * $Id: prepend.php3,v 1.4 2009/08/06 bwiest@maglin.com Exp $
 *
 */

$_PHPLIB = array();
$_PHPLIB["libdir"] = "/usr/local/lib/phplib/";

require($_PHPLIB["libdir"] . "db_mysql.inc");  /* Change this to match your database. */
require($_PHPLIB["libdir"] . "ct_sql.inc");    /* Change this to match your data storage container */
require($_PHPLIB["libdir"] . "session.inc");   /* Required for everything below.      */
#require($_PHPLIB["libdir"] . "auth.inc");      /* Disable this, if you are not using authentication. */
#require($_PHPLIB["libdir"] . "perm.inc");      /* Disable this, if you are not using permission checks. */
#require($_PHPLIB["libdir"] . "user.inc");      /* Disable this, if you are not using per-user variables. */

/* Additional require statements go below this line */
# require($_PHPLIB["libdir"] . "menu.inc");      /* Enable to use Menu */

/* Additional require statements go before this line */

require($_PHPLIB["libdir"] . "local.inc");     /* Required, contains your local configuration. */

require($_PHPLIB["libdir"] . "page.inc");      /* Required, contains the page management functions. */

require("/usr/local/apache2/php/include/aokfunctions.inc");

?>


On the Windows machine, this file causes the first parse error I reported,.on line 19 (the line having the first require() statement.

The fille on the Windows machine, has been modifed, of course, with respect to directory references:

<?php
/*
 * Session Management for PHP3
 *
 * Copyright (c) 1998-2000 NetUSE AG
 *                    Boris Erdmann, Kristian Koehntopp
 *
 * $Id: prepend.php3,v 1.4 2001/07/14 20:24:55 kk Exp $
 * $Id: prepend.php3,v 1.4 2009/08/06 bwiest@maglin.com Exp $
 *
 */


$_PHPLIB = array();
//$_PHPLIB["libdir"] = "/usr/local/lib/phplib/";

$_PHPLIB["libdir"] = "c:\phplib\";

require($_PHPLIB[libdir] . 'db_mysql.inc');  /* Change this to match your database. */
require($_PHPLIB["libdir"] . "ct_sql.inc");    /* Change this to match your data storage container */
require($_PHPLIB["libdir"] . "session.inc");   /* Required for everything below.      */
#require($_PHPLIB["libdir"] . "auth.inc");      /* Disable this, if you are not using authentication. */
#require($_PHPLIB["libdir"] . "perm.inc");      /* Disable this, if you are not using permission checks. */
#require($_PHPLIB["libdir"] . "user.inc");      /* Disable this, if you are not using per-user variables. */

/* Additional require statements go below this line */
// require($_PHPLIB["libdir"] . "menu.inc");      /* Enable to use Menu */

/* Additional require statements go before this line */

require($_PHPLIB["libdir"] . "local.inc");     /* Required, contains your local configuration. */

require($_PHPLIB["libdir"] . "page.inc");      /* Required, contains the page management functions. */

//require("/usr/local/apache2/php/include/aokfunctions.inc");

require("C:\inetpub\wwwroot\html\aloak.ca\maglin\include\aokfunctions.inc");

?>

Note that, with the modificattions made to line 19 in the above file, there are no parse errors on the Windows machine. However, it baffles me that there should have been any in the first place.  The parse error I reported above now shows up on line 20, in the second require() statment.

Thanks

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36539047
Please use the code snippet to post code and things like this.  It gives us line numbers.  When things are posted in the question body, it is almost impossible to know what line the error message might point to, because we have not line numbers.
0
 

Author Comment

by:MaglinFurniture
ID: 36539087
File from Linux server:

<?php
/*
 * Session Management for PHP3
 *
 * Copyright (c) 1998-2000 NetUSE AG
 *                    Boris Erdmann, Kristian Koehntopp
 *
 * $Id: prepend.php3,v 1.4 2001/07/14 20:24:55 kk Exp $
 * $Id: prepend.php3,v 1.4 2009/08/06 bwiest@maglin.com Exp $
 *
 */

$_PHPLIB = array();
$_PHPLIB["libdir"] = "/usr/local/lib/phplib/";

require($_PHPLIB["libdir"] . "db_mysql.inc");  /* Change this to match your database. */
require($_PHPLIB["libdir"] . "ct_sql.inc");    /* Change this to match your data storage container */
require($_PHPLIB["libdir"] . "session.inc");   /* Required for everything below.      */
#require($_PHPLIB["libdir"] . "auth.inc");      /* Disable this, if you are not using authentication. */
#require($_PHPLIB["libdir"] . "perm.inc");      /* Disable this, if you are not using permission checks. */
#require($_PHPLIB["libdir"] . "user.inc");      /* Disable this, if you are not using per-user variables. */

/* Additional require statements go below this line */
# require($_PHPLIB["libdir"] . "menu.inc");      /* Enable to use Menu */

/* Additional require statements go before this line */

require($_PHPLIB["libdir"] . "local.inc");     /* Required, contains your local configuration. */

require($_PHPLIB["libdir"] . "page.inc");      /* Required, contains the page management functions. */

require("/usr/local/apache2/php/include/aokfunctions.inc");

?>

Open in new window

0
 

Author Comment

by:MaglinFurniture
ID: 36539103
Line 16 in the above snippet is referred to as line 19 when the parse error is reportd. What follows is the equivalent file that is on the Windows machine.

<?php
/*
 * Session Management for PHP3
 *
 * Copyright (c) 1998-2000 NetUSE AG
 *                    Boris Erdmann, Kristian Koehntopp
 *
 * $Id: prepend.php3,v 1.4 2001/07/14 20:24:55 kk Exp $
 * $Id: prepend.php3,v 1.4 2009/08/06 bwiest@maglin.com Exp $
 *
 */


$_PHPLIB = array();
//$_PHPLIB["libdir"] = "/usr/local/lib/phplib/";

$_PHPLIB["libdir"] = "c:\phplib\";

require($_PHPLIB[libdir] . 'db_mysql.inc');  /* Change this to match your database. */
require($_PHPLIB["libdir"] . "ct_sql.inc");    /* Change this to match your data storage container */
require($_PHPLIB["libdir"] . "session.inc");   /* Required for everything below.      */
#require($_PHPLIB["libdir"] . "auth.inc");      /* Disable this, if you are not using authentication. */
#require($_PHPLIB["libdir"] . "perm.inc");      /* Disable this, if you are not using permission checks. */
#require($_PHPLIB["libdir"] . "user.inc");      /* Disable this, if you are not using per-user variables. */

/* Additional require statements go below this line */
// require($_PHPLIB["libdir"] . "menu.inc");      /* Enable to use Menu */

/* Additional require statements go before this line */

require($_PHPLIB["libdir"] . "local.inc");     /* Required, contains your local configuration. */

require($_PHPLIB["libdir"] . "page.inc");      /* Required, contains the page management functions. */

//require("/usr/local/apache2/php/include/aokfunctions.inc");

require("C:\inetpub\wwwroot\html\aloak.ca\maglin\include\aokfunctions.inc");

?>

Open in new window

0
 

Author Comment

by:MaglinFurniture
ID: 36539120
In the Windows version of the file, line 19 is now modified to get rid of the parse errors. But, as I mentioned, I don't understand why these modifications should be required. Should be able to use double quotes, as in the original file that is on the Linux machine.

Note also, I made a modification to line 37, as the file referred to there is no longer in the IIS webroot (I had been using IIS before I decided to install Apache)

0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 350 total points
ID: 36539482
There is a context-aware directory separator constant that should be used instead of the slash when you want to make your code portable.  It is named, conveniently, DIRECTORY_SEPARATOR.  You can use it like shown in the code snippet.

This script outputs something like.
Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in /path/to/RAY_temp_maglin.php on line 8

The failure occurs because the backslash is an escape character when used inside a double-quoted string.  IIRC, it may be an escape character when used inside a single-quoted string and that is content-dependent.  But in any case, switch from using the slash to using DIRECTORY_SEPARATOR and you will be fine.

In related news there is a context-aware end of line character, PHP_EOL.  Much safer than using \r or \n or \r\n

Best regards, ~Ray
<?php // RAY_temp_maglin.php
error_reporting(E_ALL);

// WORKS
$_PHPLIB["libdir"] = "c:" . DIRECTORY_SEPARATOR . "phplib" . DIRECTORY_SEPARATOR;

// FAILS
$_PHPLIB["foobar"] = "c:\phplib\";

Open in new window

0
 
LVL 19

Expert Comment

by:bevhost
ID: 36541067
Try
$_PHPLIB["libdir"] = "c:\\phplib\\";
0
 
LVL 19

Assisted Solution

by:bevhost
bevhost earned 150 total points
ID: 36541099
Or
$_PHPLIB["libdir"] = "c:/phplib/";
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 19

Expert Comment

by:bevhost
ID: 36541100
Or
$_PHPLIB["libdir"] = "c:/phplib/";
0
 
LVL 19

Expert Comment

by:bevhost
ID: 36541814
Code segments don't appear on EE Mobile.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36542195
@bevhost: I believe the central issue here is the use of the slash as a directory separator character.  The author moved PHP scripts between Linux and Windows systems.  These systems use different slashes for the directory separator.  The predefined, context-aware PHP constant DIRECTORY_SEPARATOR is what you want to use if you want portability between systems.  The code segment that was invisible to you is shown below:  

<?php // RAY_temp_maglin.php
error_reporting(E_ALL);

// WORKS
$_PHPLIB["libdir"] = "c:" . DIRECTORY_SEPARATOR . "phplib" . DIRECTORY_SEPARATOR;

// FAILS
$_PHPLIB["foobar"] = "c:\phplib\";
0
 

Author Comment

by:MaglinFurniture
ID: 36542529
Will get back to you asap.

Thanks.
0
 

Author Comment

by:MaglinFurniture
ID: 36543345
I've done some testing and agree that the central issue does seem to be the use of a slash, specifically a backslash, as a directory separator, when the backslash precedes a quotation mark. In this case, the backslash is interpreted as an escape character.

I have confirmed that using

$_PHPLIB["libdir"] = "c:/phplib/";

works.

Once this issue is resolved, there is no need to change from using double quotes to single quotes, etc.

Although I am sure that using DIRECTORY_SEPARATOR will work, it is a lot more typing than / :)

Thanks all for taking the time to reply to this.

0
 

Author Closing Comment

by:MaglinFurniture
ID: 36543377
I awarded greator points to Ray Paseur on the assumption of his having done more testing. Hope that assumption was accurate.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36543614
Thanks for the points.  I usually test code before I post it here, or at least give a warning that I am posting untested code.  Sometimes that is unavoidable, such as when I do not have access to test data.  Not everyone at EE tests the solutions before posting, so it is always wise to test before you consume!
0
 
LVL 19

Expert Comment

by:bevhost
ID: 36546693
I am personally interested to hear more about what you are using PHPLIB for .
It is a VERY old PHP library which I have been using since PHP3.
I have modified it extensively to make it work with PHP4&5, mysqli and to have it work with register_globals = Off

I have also modified the table class to allow in cell editing, among other things.

If you are interested see http://www.beveridge.id.au/david/
0
 

Author Comment

by:MaglinFurniture
ID: 36549090
Directory references and PHPLIB

@all
Interestingly enough, there are several directory references in the PHP files on our website which work "as is" on the Windows machine, which I was very happy to discover. Things like "/html/etc/etc" whiich, on the Windows machine are off of Drive C: all wokr without any need to add c: in front of them. I love Apache.

@bevhost
We use PJPLIB for session management, and have used it since it came out. It IS very old and interestingly, when I had to upgrade the Maglin website about 3 years ago, I read an article about it on Wikipedia, claiming it was "outdated", or "deprecated", is what I believe it actuallly said. I thought this was rediculous, as it is a very robust session mangement system and I could not find anything else to use. I know that, with PHP4, there was a built-in session management system available, but I recall reading in the PHP manual on php.net all sorts of dire warnings AGAINST using it, and half the functions didn't work anyway.

The authors of PHPLIB made an attemtp to "upgrade" the library for PHP 4. I tried to install that upgraded library when I started working on upgrading the Maglin website, but it didn't work and I did not have time to figure out all the ins and outs of the code to figure why, so I gave up on that and went back to using the latest version that had been available for PHP3, which we had used for many years in other website projects. I did have to modify all the references to deprecated Arrays, etc. such as changing $HTTP_POST_VARS to $_POST, etc.

I am sure you have done a great deal more work to modify PHPLIB with it than I have. As I said, we use it only for session management. My time constraints never allow me to do much other than what is absolutely necessary at any given time., so I've never investigated this library beyond the need to get session mangement working for the upgraded website, which uses PHP 5.3, MySQL 1.5.1.36, and Apache 2.2.11.

I'm not sure what the current status is rearding support etc for PHPLIB. I notice that you can't find ANY reference to it on Wikipedia now, but there are active links to it when you do a Google search (links dated recently, not just from years back. I modifed phplib-7.2d for use on the Maglin website, and I see you can download phplib-7.4.from SourceForge, and that there is a link on the download page to a develoopment site for PHPLIB, so maybe development has resumed.

I'll take a look at the link you have posted.

Thanks.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
OfficeMate Freezes on login or does not load after login credentials are input.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now