I am working with two seperate files which contain similar code - One throws a parse error for an identical line, the other does not. I do not understand why this would be.

The error on the file that will not run is: Parse error: syntax error, unexpected '2' (T_LNUMBER)

Here is a code snippet that works without the parse error:

if (($indx % 2) == 1) {$rowClass = $trOdd; } else { $rowClass = $trEven; } echo '<tr '.$rowClass.'>';

Here is a code snippet that does not work and has the parse error:

if (($indx % 2) == 1) {$rowClass = $trOdd; } else { $rowClass = $trEven; } echo '<tr '.$rowClass.'>';

Identical.

This error centers around the use of the 2, hence the (T_LNUMBER).

I see no difference in either code - I am simply doing ($indx % 2) == 1), the 2 being the problem for some reason.

Thank you in advance for any help!

Dani AI

Generated

Short summary and concrete troubleshooting steps.

T_LNUMBER means the PHP parser encountered a numeric literal where it did not expect one — in practice that usually means an operator or other token is missing (so the parser complains about the "2" token). As discovered, retyping the missing operator fixed the file; that strongly suggests an editor/character issue rather than a language bug.

Practical steps to find the real cause:

  • Run the PHP linter to confirm the location:
    php -l yourfile.php
  • Inspect the exact bytes around the failing line to reveal invisible characters or a missing ASCII operator (on Unix-like systems):
    nl -ba yourfile.php | sed -n '110,120p'
    hexdump -C yourfile.php | sed -n '110,120p'

    On Windows, open the file in an editor that can “show all characters” (Notepad++: View→Show Symbol→Show All Characters) or use a hex viewer plugin.

  • Compare the broken file to a working copy with a binary diff to see any byte-level differences:
    diff -u working.php broken.php

Likely culprits and fixes

  • Invisible/non-ASCII character replaced or removed (e.g., non-breaking space or editor bug). Re-type the line in a different editor, save, and re-test.
  • File encoding/BOM problems (save as UTF-8 without BOM or as plain ASCII).
  • Editor-specific bug (Bluefish): try saving with a different editor or update Bluefish and disable any auto-replace plugins.

Workflow tips to avoid this in future

  • Use php -l as part of your save/lint workflow.
  • Enable “show invisible characters” in your editor.
  • Keep changes in version control so you can diff and revert easily.

Good practice, as requested, is to post the linter output and the minimal surrounding lines when reporting parse errors — that makes diagnosis faster.

Recommended Answers

All 3 Replies

what's the rest of the error message

also post more of the code around the erroring line

Hi,

The complete error message is: Parse error: syntax error, unexpected '2' (T_LNUMBER) in C:\xampp\htdocs\demo\nest_Demo_thrasher.php on line 115

The full code for the file in question:

<?php
/*

*   File:       nest_Demo.php
*   By:         TMIT
*   Date:       2010-06-01
*
*   This script demonstrates elegant nested rendering
*       using SQL rather than a language construct
*       
*
*=========================================================================
*/

{       //  Secure Connection Script
        include('../../htconfig/dbConfig.php'); 
        $dbSuccess = false;
        $dbConnected =    mysql_connect($db['hostname'],$db['username'],$db['password']);

        if ($dbConnected) {     
            $dbSelected = mysql_select_db($db['database'],$dbConnected);
            if ($dbSelected) {
                $dbSuccess = true;
            } else {
                echo "DB Selection FAILed";
            }
        } else {
                echo "MySQL Connection FAILed";
        }
        //  END Secure Connection Script
}

if ($dbSuccess) {

    {  //   Style declarations
            $trOdd = 'style = "background-color: #BFFFCF;"';
            $trEven = 'style = "background-color: #FCCDFF;"';

            $textFont = 'style = " font-family: arial, helvetica, sans-serif; "';
            $textRed = 'style = " font-family: arial, helvetica, sans-serif; color:maroon; "';

            $indent50 = 'style = " margin-left: 50; "';
            $indent100 = 'style = " margin-left: 100; "';

    //   END: Style declarations    
    }

    echo '<h1>All Persons by Company</h1>';

    {   //      SQL
    $tPerson_SQLselect = "SELECT  ";
    $tPerson_SQLselect .= "tPerson.ID AS personID, ";   
    $tPerson_SQLselect .= "tPerson.Salutation, ";   
    $tPerson_SQLselect .= "tPerson.FirstName, tPerson.LastName, ";  



    $tPerson_SQLselect .= "tCompany.ID AS companyID, ";     
    $tPerson_SQLselect .= "tCompany.preName, tCompany.Name, tCompany.RegType "; 
    $tPerson_SQLselect .= "FROM tPerson LEFT JOIN tCompany ";
    $tPerson_SQLselect .= "ON tPerson.CompanyID = tCompany.ID ";
    $tPerson_SQLselect .= "ORDER BY tCompany.Name, tCompany.preName, tCompany.ID, ";
    $tPerson_SQLselect .= "tPerson.LastName, tPerson.FirstName ";

    $tPerson_SQLselect_Query = mysql_query($tPerson_SQLselect);
    //      END:  SQL   
    }       
    $currentCompanyID = -1;
    $indx = 0;
    echo '<div '.$textFont.'>';

    while ($row = mysql_fetch_array($tPerson_SQLselect_Query, MYSQL_ASSOC)) {

            {   //  assign variables to row data 
                $personID = $row['personID'];
                $Salutation = $row['Salutation'];
                $FirstName = $row['FirstName'];
                $LastName = $row['LastName'];
                $Telephone = $row['Telephone'];
                $eMail = $row['eMail'];

                $CompanyID = $row['companyID'];
                $CompanypreName = $row['preName'];
                $CompanyName = $row['Name'];
                $CompanyRegType = $row['RegType'];

                $CompanyFullName = trim($CompanypreName." ".$CompanyName." ".$CompanyRegType);
            //  END:  assign variables to row data 
            }

            {   //      Company header 
                if (empty($CompanyID)) {
                    $CompanyID = 0;
                    $CompanyFullName = "UN-Allocated";
                }   

               if ($CompanyID <> $currentCompanyID) {

                   if ($currentCompanyID <> -1) {
                //      Render the table tail 
                        echo "</table>"; 
                        echo '</div>';
                }

                //      Render the company header
                echo '<h2 '.$indent50.'>'.$CompanyFullName.'</h2>';

                    echo '<div '.$indent100.'>';
                echo "<table border='1'>";
                    echo "<tr>";

                        echo "<td>#</td>";
                        echo "<td>Salutation</td>";
                        echo "<td>FirstName</td>";
                        echo "<td>LastName</td>";
                        echo "<td>Telephone</td>";
                        echo "<td>eMail</td>";

                    echo "</tr>";  

                //      
               } 
                    $currentCompanyID = $CompanyID;
            //  END:   Company header 
            }   

            {   //      Create and format a row for each person
            if (($indx % 2) == 1) {$rowClass = $trOdd; } else { $rowClass = $trEven; }
            echo '<tr '.$rowClass.'>';


                echo "<td>".$personID."&nbsp;</td>";       //  this is NOT  tPerson.ID
                echo "<td>".$Salutation."&nbsp;</td>";
                echo "<td>".$FirstName."&nbsp;</td>";
                echo "<td>".$LastName."&nbsp;</td>";
                echo "<td>".$Telephone."&nbsp;</td>";
                echo "<td>".$eMail."&nbsp;</td>";

            echo "</tr>";
            }   //      END:  Create and format a row for each person

            $indx++;

    //     END:  while ($row = mysql_fetch_array($tPerson_SQLselect_Query
    }

    echo '</div>';

    mysql_free_result($tPerson_SQLselect_Query);        
}

?>

`

This has been solved.

It seems like it was an issue with my code editor (BlueFish) or something.

When I removed the % in ($indx % 2) == 1), saved the file, and ran it I received the same error as noted in my original post.

I then re-added % to ($indx 2) == 1), saved it, ran it and it worked.

Not sure what happened there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.