Welcome! » Log In » Create A New Profile

PHP(4) Parse error

Posted by Franz Alt 
Franz Alt
PHP(4) Parse error
June 27, 2007 06:47AM

Dear Programmers, dear forum,

Because I get Parse errors in "PHProjekt.com" with the HTMLPurifier library, I downloaded your lastest Version for PHP 4 today and tried to parse with php Version 4.4.7

> find . -name "*.php" -exec php -l {} \; | grep -v "No syntax error"

Output:

  • PHP Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in ./library/HTMLPurifier/Lexer/DOMLex.php on line 33
  • Errors parsing ./library/HTMLPurifier/Lexer/DOMLex.php
  • PHP Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in ./library/HTMLPurifier/TokenFactory.php on line 24
  • Errors parsing ./library/HTMLPurifier/TokenFactory.php

I could fix some of this parsing errors, by

  • deleting keywords "private"/"public" or replacing by "var"
  • using clone-workaround in [acko.net]

I could not get line 63 to 67 in DOMLex.php working.

        $this->tokenizeDOM(
            $doc->getElementsByTagName('html')->item(0)-> // <html>
                  getElementsByTagName('body')->item(0)-> //   <body>
                  getElementsByTagName('div')->item(0)    //     <div>
            , $tokens);

Any Idea why there are this parsing errors and how to fix them?

Regards Franz

Edited 2 time(s). Last edit at 06/29/2007 12:09AM by Ambush Commander.

Re: PHP(4) Parse error
June 27, 2007 08:49AM

Hi, your lint program is being overly aggressive. DOMLex is a bit of PHP5 specific code that HTML Purifier will automatically refrain from including if you're running PHP4. Try running it and things will work fine. (TokenFactory is a similar file)

BTW, PHProjekt's running an out-of-date version... you may want to upgrade it yourself.

HTML Purifier, Standards Compliant HTML Filtering

Franz Alt
Re: PHP(4) Parse error
June 27, 2007 11:33AM

Thank's for answering so quick!

Unfortunately I don't know a way to make `php -l` less "aggressive".

Is there a way to tell PHP4 not to look at this part of code, since it isn't executed?

E.g. with "IF DEFINED ..." Macros for something like "conditioned compiling" in C or switching diffent Browsers with "Conditional Comments" for Internet Explorer?

Re: PHP(4) Parse error
June 27, 2007 11:36AM

Well, technically speaking, it should just "work". php -l is simply advisory, right?

If it's a blocker for you, simply remove DOMLex.php and TokenFactory.php from the file tree and php -l will come up clean.

Franz Alt
Re: PHP(4) Parse error
June 27, 2007 12:38PM

Yes, "advisory", because we handle a lot of php-scripts and we have a "no notice"-policy and automatic e-mail-notification if this policy is violated.

So I will delete this 2 files.

Thanks so far!

Author:
Subject:

HTML input is enabled. Make sure you escape all HTML and angled brackets with &lt; and &gt;.

Auto-paragraphing is enabled. Double newlines will be converted to paragraphs; for single newlines, use the pre tag.

Allowed tags: a, abbr, acronym, b, blockquote, caption, cite, code, dd, del, dfn, div, dl, dt, em, i, ins, kbd, li, ol, p, pre, s, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var.

For inputting literal code such as HTML and PHP for display, use CDATA tags to auto-escape your angled brackets, and pre to preserve newlines:

<pre><![CDATA[
Place code here
]]></pre>

Power users, you can hide this notice with:

.htmlpurifier-help {display:none;}

Message: