I am building an php include file. At the top, declared public and private variables contain both simple values and mathematical expressions. Those that include math within the declaration, such as $a=$b+$c, throw a syntax error. The strange thing is that php takes similar variable declarations in the calling file without complaint. There are many examples of mathematical expressions within variable declarations on the web, so it appears to be a legal practice. Whether I run the include file from the calling file or by directly accessing it in a browser, essentially the same error message occurs.
Below I have included (1) the error message, (2) the entire include file, and (3) a portion of the main file that calls the include file. I would appreciate any thoughts or suggestions on this problem. Thanks for your help.
(1) The error message:
Parse error: syntax error, unexpected T_VARIABLE in /srv/www/htdocs/PNS/class.tablePagination.php on line 7
(2) Code from the include file generating the error:
<?php
class pagination
{
private $limit = 30;
private $start = 0;
private $eu = $start -0;
private $space = " - ";
$this1 = $eu - $limit;
private $back = $eu - $limit;
private $next = $eu + $limit;
private $k = $j + $limit;
public $beg;
public $end;
public function page()
{
private $eu = $start -0;
$sql="select * FROM Complex"; /////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
$result = $db->query($sql);
echo mysql_error();
$nume=mysqli_num_rows($result); // $nume is the total number of rows in the table.
//echo 'Row numbers= ' . $nume;
$p_limit=30; // Variables set for advance paging - should be more than $limit and set to a value for which links to be breaked
$p_f=$_GET['p_f']; // To take care global variable if OFF
if(!($p_f > 0))
{ // This variable is set to zero for the first page
$p_f = 0;
}
$p_fwd=$p_f+$p_limit;
$p_back=$p_f-$p_limit;
//////////// End of variables for advance paging ///////////////
/////////////// Start the buttom links with Prev and next link with page numbers /////////////////
echo $space . $p_f . $space . $p_f . $space . $p_limit;
$sql="select * FROM Complex order by Name limit " . $j . ", " . $k; // record set for subsequent page displays
$result=$db->query($sql);
echo "<table align = 'center' " . $width . "><tr><td align='left' width='20%'>";
//if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back'><font face='Verdana' size='2'>PREV $p_limit</font></a>"; }
if($p_f<>0){print "<font face='Verdana' size='2'>PREV $p_limit</font>"; }
echo "</td><td align='left' width='20%'>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0 and ($back >=$p_f))
{
//print "<a href='$page_name?start=$back&p_f=$p_f'><font face='Verdana' size='2'>PREV</font></a>";
print "<font face='Verdana' size='2'>PREV</font>";
}
//////////////// Let us display the page links at center. We will not display the current page as a link ///////////
echo "</td><td align=center width='20%'>";
for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit)
{
$j=$i+1;$k=$j+$limit;
if($i <> $eu)
{
$i2=$i+$p_f;
//echo " <a href='$page_name?start=$i&p_f=$p_f'><font face='Verdana' size='2'>Records $j - $k</font></a> ";
echo " <font face='Verdana' size='2'>Records $j - $k</font> ";
}
else { $j=$i+1;$k=$j+$limit;echo "<font face='Verdana' size='2' > Records $j - $k</font>";} /// Current page is not displayed as link
}
echo "</td><td align='right' width='40%'>";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume and $this1 <($p_f+$p_limit))
{
//print "<a href='$page_name?start=$next&p_f=$p_f'><font face='Verdana' size='2'>NEXT $p_limit</font></a>";
print "<font face='Verdana' size='2'>NEXT $p_limit</font>";
}
echo "</td><td align='right' width='40%'>";
if($p_fwd < $nume)
{
//print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'><font face='Verdana' size='2'>NEXT $p_limit</font></a>";
print "<font face='Verdana' size='2'>NEXT $p_limit</font>";
}
echo "</td></tr>";
echo "</table>";
$this->$beg = $j;
$this->$end = $k;
return $j;$k;
}
}
?>
(3) Code from the top of the calling file: - It's lengthy, so I only posted the top portion. Note the last line, which contains addition within the variable declaration. No error is generated.
<html>
<head>
<title>Complex Test7</title>
<link href="css/styles.css" rel="stylesheet" type="text/css">
<! <link href="css/styles.php" rel="stylesheet" type="text/css">
</head>
<body class="tablefonts">
<center>TEST7</center>
<?php
require ('PNS_Styles.php');
require ('class.dbConnect.php');
require ('class.tablePagination.php');
$db=' ';
$result = "";
$empty = "<td><center><b> --- Empty --- </b></td></center>";
$page_name="complexTest6.php"; // If you use this code with a different page ( or file ) name then change this
//$limit = 30; // No of records to be shown per page.
$i=1;
$j=0;
$p_f=0;
$k=$j+$limit;