Jump to content

unexpected T_PUBLIC


no_one

Recommended Posts

Back to this again. I went through all my code, line-by-line, and found nothing wrong. I did a few other things to check for problems. I didn't figure I'd find any, since the problem makes no sense.

 

The site I've been programming is nearly finished (on hold because of this problem) so I uploaded (for the first time) all files to my host server and got an error, after altering a few things (no real coding, just code cleanup while looking at every line), I get a different error, but the same file, same class, and same general area.

 

Parse error: syntax error, unexpected T_PUBLIC in /dir/file.php on line 31

(Note: dir/file.php isn't the real file path.. but w/e).

 

<?php
class myclass 
{
    public function __construct()  // line 30
    {  // <-- line 31

?>

 

I've also deleted the 'public' as a test and still got the error.

 

The problem I'm having is even after updating all my software to match or go higher than my host's versions (php 5.2.2) the code runs perfect on my computer, but I get the above error on the host. I do have error reporting set to show everything.

 

I checked for unmatched brackets/braces/quotes, missing semi-colons, colons where it should be semi, etc. Nothing wrong AFAI-Can see..

 

Any suggestions? I'm seriously losing my mind.  If not, then all I can think to do is get another host for a month and see if I get the same problem.

Link to comment
Share on other sites

Hi  :D

 

Ty for the suggestion. Just tried it, and still got the same error, same line (the line where the echo is). Below is is the basic set up, the only thing that needed changing was moving the __ctor() open curly, and putting in an echo.

 

Someone already pointed out the semi-colon on the end of my class, it doesn't hurt anything that I can see (I've removed them and still no help).

 

<?php
require_once("required.php");

class mclass 
{
    public function __construct(){
        echo "page_construct";

        $this->somemethod();
    }

    /// other class code..
};

// ... 

$mc = new mclass(); 
?>

Link to comment
Share on other sites

  • 2 years later...

I am experiencing the very same thing. Works completed fine on my development machine but breaks when I upload it to the server. Could use a second pair of eyes.

 

<?
class DataGrid
{
private $Properties 	= array();
private $columns 		= array();
private $colsByIndex 	= array();
private $customCol 		= array();
private $customCommand 	= array();
private $filters 		= array();

/**
 * Object property setter method
 * 
 * @access Public
 * @param String $name
 * @param Mixed $value
 */
public function __set($name, $value)
{
	$this->Properties[$name] = $value;
}

/**
 * Object property getter method
 * 
 * @access Public
 * @param String $name
 */
public function __get($name)
{
	return array_key_exists($name, $this->Properties) ? $this->Properties[$name] : null;
}

public function __construct($ID=null, $tableName=null, $dataKeyName=null, $enableEdit=null, $endableUpdate=null, $enableDel=null, $enableInsert=null, $enableSel=null, $enableSort=null)
{

	$this->ID 			= empty($ID) ? null : $ID;
	$this->Name 		= $this->ID;
	$this->Height 		= '';
	$this->Width 		= '';
	$this->CellPadding 	= 1;
	$this->CellSpacing 	= 1;
	$this->Border 		= 0;
	$this->Visible 		= true;
	$this->ButtonType 	= 'image';
	$this->CssClass 	= '';
	$this->Style 		= '';

	$this->TableName 		= empty($tableName) 	? null 		: $tableName;
	$this->DataKeyName 		= empty($dataKeyName) 	? null 		: $dataKeyName;
	//$this->SelectCommand 	= empty($selectCmd) 	? null 		: $selectCmd;
	//$this->UpdateCommand 	= empty($updateCmd) 	? null 		: $updateCmd;
	//$this->DeleteCommand 	= empty($delCmd) 		? null 		: $delCmd;
	$this->EnableEditing 	= empty($endableUpdate) ? false 	: $endableUpdate;
	$this->EnableUpdating 	= empty($enableEdit) 	? false 	: $enableEdit;
	$this->EnableDeleting 	= empty($enableDel) 	? false 	: $enableDel;
	$this->EnableInsert 	= empty($enableInsert) 	? false 	: $enableInsert;
	$this->EnableSorting 	= empty($enableSort) 	? false 	: $enableSort;
	$this->EnableSelect 	= empty($enableSel) 	? false 	: $enableSel;

	$this->EditText 	= 'Edit';
	$this->DeleteText 	= 'Delete';
	$this->CancelText 	= 'Cancel';
	$this->SelectText 	= 'Select';
	$this->InsertText 	= 'Insert';

	$this->EditImageUrl 	= '';
	$this->SelectImageUrl 	= '';
	$this->DeleteImageUrl 	= '';
	$this->InsertImageUrl 	= '';
	$this->CancelImageUrl 	= '';

	$this->object 	= isset($_GET['obj']) 		? $_GET['obj'] 		: null;
	$this->task 	= isset($_GET['task']) 		? $_GET['task'] 	: null;
	$this->subtask 	= isset($_GET['subtask']) 	? $_GET['subtask'] 	: null;
	$this->param 	= isset($_GET['id']) 		? $_GET['id'] 		: null;
}

/**
 * Enter Description here...
 * 
 * @access Public
 * @return Void
 */
public function __destruct()
{
}

/**
 * Enter description here...
 *
 * @access Public
 * @param string $logic
 * @param string $name
 * @param string $operator
 * @param variant $value
 * @return Void
 */
public function AddFilter($logic=null,$name=null,$operator=null,$value=null)
{
	if(is_string($value))
		$value = '"'.$value.'"';
		//$value = "'$value'";

	$this->filters[] = $logic.' '.$name.' '.$operator.' '.$value.' ';
}

/**
 * Enter description here...
 *
 * @access Public
 * @param string $tableName
 * @param string $cols
 * @return Void
 */
public function SetSelect($cols=null)
{
	if($this->SelectCommand == '')
	{
		$filter = '';
		$newcols = '';

		if(is_array($this->filters) && count($this->filters) > 0)
		{
			$filter = " WHERE ";
			for($x=0; $x < count($this->filters); $x++)
			{
				$filter .= $this->filters[$x];
			}
		}

		if(is_array($this->columns) && count($this->columns) > 0)
		{
			foreach ($this->columns as $key => $value)
			{
				$newcols .= $key . " AS '".$value."', ";
			}
			$this->SelectCommand = 'SELECT '.$this->DataKeyName.','.substr($newcols,0,strrpos($newcols,',')).' FROM '.$this->TableName.$filter;
		}else
		{
			$this->SelectCommand = 'SELECT '.$this->DataKeyName.','.$cols.' FROM '.$this->TableName.$filter;
		}
	}
}

/**
 * Enter description here...
 *
 * @access Public
 * @param string $tableName
 * @param string $cols
 * @return Void
 */
public function Bind($cols=null)
{
	$this->setSelect($this->TableName,$cols);
}

/**
 * Enter description here...
 *
 * @access Public
 * @return String
 */
public function Display()
{
	$this->Bind();

	$cntr = 0;
	$printed_headers = false;
	$isCustom = '';
	$colAlign = '';

	$return = 	'<div id="'.$this->ID.'">'.NEW_LINE.
				'<form name="'.$this->ID.'" method="post">'.NEW_LINE.
				'<table '.
					'cellpadding="'.$this->CellPadding.'" '.
					'cellspacing="'.$this->CellSpacing.'" '.
					'border="'.$this->Border.'" '.
					'height="'.$this->Height.'" '.
					'width="'.$this->Width.'" '.
					'style="'.$this->Style.'" '.
					'class="'.$this->CssClass.'">'.NEW_LINE;

	if($this->controler($this->subtask, $this->param, $_POST) != '')
	{
		$this->Database->Open();
		$this->Database->execute($this->controler($this->subtask,$this->param,$_POST));
		$this->Database->Close();
		header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'?obj='.$this->object.'&task='.$this->task.'&subtask=&id=');
	}else
	{
		$this->Database->Open();
		$rs = $this->Database->getRecordset($this->SelectCommand);

		if($this->Database->getRowCount($rs) > 0)
		{
			while($row = $this->Database->getRecords($rs))
			{
				$count = 0;
				if(!$printed_headers)
				{
					//print the headers once:
					$return .= '<tr>'.NEW_LINE;

					if($this->EnableEditing || $this->EnableDeleting || $this->EnableSelecting)
						$return .= '<th width="25"> </th>'.NEW_LINE;

					foreach(array_keys($row) AS $header)
					{
						//you have integer keys as well as string keys because of the way PHP handles arrays.
						if(!is_int($header) && $header != $this->DataKeyName)
							$return .= '<th nowrap>'.$header.'</th>'.NEW_LINE;
					}

					$return .= '</tr>'.NEW_LINE;
					$printed_headers = true;
				}
			    
				//print the data row
				$return .= '<tr'.$this->alter($cntr).'><a name="'.$row[$this->DataKeyName].'">'.NEW_LINE;

				if($this->EnableEditing || $this->EnableDeleting)
					$return .= '<td nowrap align="center">'.$this->GetCommandButtons($this->subtask, $this->param, $row[$this->DataKeyName]).'</td>'.NEW_LINE;

				foreach($row AS $key=>$value)
				{
					if(!is_int($key) && $key != $this->DataKeyName)
					{
						if(is_array($this->customCol) && $this->customCol[$count] == $this->colsByIndex[$count])
						{
							$isCustom = true;
							$colAlign = ' align="center" ';
						}else
						{
							$isCustom = false;
							$colAlign = ' align="left" ';
						}

						$return .= '<td'.$this->isFirst($cntr).$colAlign.'>';

						if($this->param == $row[$this->DataKeyName])
						{
							// Check to see if we need to show a custom column
							if($isCustom)
								$return .= '<a href="'.$this->customCommand[$count].'&id='.$value.'" title="Edit"><img src="'.$this->EditImageUrl.'" border="0"></a>';
							else
								$return .= '<input type="text" name="'.$this->colsByIndex[$count].'" value="'.$value.'" style="width:100%;" class="">';

						}elseif($this->param != $row[$this->DataKeyName])
						{
							// Check to see if we need to show a custom column
							if($isCustom)
								$return .= '<a href="'.$this->customCommand[$count].'&id='.$value.'" title="Edit"><img src="'.$this->EditImageUrl.'" border="0"></a>';
							else
								$return .= $value.' ';
						}

						$return .= '</td>'.NEW_LINE;
						$count++;
					}
				}
				$return .= '</tr>'.NEW_LINE;
				$cntr++;
			}
			$this->Database->release($rs);
		}
	}

	$return .= 	'</table>'.NEW_LINE.
				'</form>'.NEW_LINE.
				'</div>'.NEW_LINE;

	$this->Database->Close();

	if($this->Visible)
		return $return;
	else
		return '';
}

/**
 * Enter description here...
 *
 * @access Public
 * @param string $name
 * @param string $text
 * @return Void
 */
public function AddColumn($name=null, $text=null, $custom=null, $obj=null, $task=null)
{
	$this->columns[$name] 	= $text;
	$this->colsByIndex[] 	= $name;

	// Add a custom column to this array index
	if($custom)
	{
		$this->customCol[] 		= $name;
		$this->customCommand[] 	= '?obj='.$obj.'&task='.$task.'&subtask=edit';
	}else // Not a custom column
	{
		$this->customCol[] 		= '';
		$this->customCommand[] 	= '';
	}
}

/**
 * Enter description here...
 *
 * @access Private
 * @param string $qsTask
 * @param integer $qsID
 * @param integer $dbID
 * @return String
 */
private function GetCommandButtons($qsTask, $qsID, $dbID)
{
	if(!isset($qsTask))
	{
		if($this->EnableEditing)
			$buttons = 	$this->GetButtonType('Edit',$dbID,$this->ButtonType,$this->EditImageUrl).NEW_LINE;

		if($this->EnableDeleting)
			$buttons.= $this->GetButtonType('Delete',$dbID,$this->ButtonType,$this->DeleteImageUrl).NEW_LINE;

	}elseif($qsID == $dbID)
	{
		$buttons = 	$this->GetButtonType('Save',$dbID,$this->ButtonType,$this->SaveImageUrl).NEW_LINE.
					$this->GetButtonType('Cancel',$dbID,$this->ButtonType,$this->CancelImageUrl).NEW_LINE;
	}elseif($qsID != $dbID)
	{
		if($this->EnableEditing)
			$buttons = 	$this->GetButtonType('Edit',$dbID,$this->ButtonType,$this->EditImageUrl).NEW_LINE;

		if($this->EnableDeleting)
			$buttons.= $this->GetButtonType('Delete',$dbID,$this->ButtonType,$this->DeleteImageUrl).NEW_LINE;
	}

	return $buttons;
}

/**
 * Enter description here...
 *
 * @access Private
 * @param string $task
 * @param integer $id
 * @param string $btnType
 * @param string $imgPath
 * @return string
 */
private function GetButtonType($task, $id, $btnType, $imgPath=null)
{
	if(strtolower($task) == 'cancel')
		$action = '?';
	else
		$action = '?obj='.$this->object.'&task='.$this->task.'&subtask='.strtolower($task).'&id='.$id.'#'.$id;

	switch (strtolower($btnType))
	{
		case 'link':
			$return = '<a href="'.$action.'" title="'.$task.'">'.$task.'</a> ';
			break;

		case 'button':
			$return = '<input type="button" name="button" value="'.$task.'" onclick="location.href=\''.$action.'\'" title="'.$task.'">';
			break;

		case 'image':
			if($task == 'Edit' && $task != 'Delete')
				$return = '<a href="'.$action.'" title="'.$task.'"><img src="'.$imgPath.'" border="0" style="padding:3px;"></a> ';
			else
			{
				if($task == 'Delete')
					$return = '<a href="'.$action.'" title="'.$task.'" onclick="return confirm(\'Are you sure you want to delete this record?\');"><img src="'.$imgPath.'" border="0" style="padding:3px;"></a> ';
				else
					$return = '<input type="image" name="button" value="'.strtolower($task).'" id="'.strtolower($task).'" title="'.$task.'" src="'.$imgPath.'" style="padding:3px;">';
			}
			break;
	}

	return $return;
}

/**
 * Enter description here...
 *
 * @access Private
 * @param string $task
 * @param integer $id
 * @param array $postVars
 * @return string
 */
private function Controler($task,$id,$postVars)
{
	$strSql = '';

	if(strtolower($task) == 'edit')
	{
		if(isset($postVars['button']))
		{
			switch(strtolower($postVars['button']))
			{
				case 'save':
					$strSql = 'UPDATE '.$this->TableName.' SET '.$this->getUpdateFields().' WHERE '.$this->DataKeyName.'='.$id;
					break;

				case 'cancel':
					header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'?obj='.$_GET['obj'].'&task='.$_GET['task'].'&subtask=&id=');
					break;
			}
		}
	}elseif(strtolower($task) == 'delete')
	{
		$strSql = 'DELETE FROM '.$this->TableName.' WHERE '.$this->DataKeyName.'='.$id;
	}

	return $strSql;
}

/**
 * Enter description here...
 *
 * @access Private
 * @return string
 */
private function GetUpdateFields()
{
	$keyValues = '';
	foreach($_POST AS $key=>$value)
	{
		if($key != 'button_x' && $key != 'button_y' && $key != 'button')
		{
			if(is_int($value))
				$keyValues .= $key."=".$value.",";
			else
				$keyValues .= $key."='".$value."',";
		}
	}
	return substr($keyValues,0,strrpos($keyValues,','));
}

/**
 * Enter description here...
 *
 * @param string $name
 * @return string
 */
private function GetColumn($name)
{
	if (array_key_exists($name, $this->columns))
		return $this->columns[$name];
	else
		return '';
}

/**
 * Enter description here...
 *
 * @return array
 */
private function GetColumns()
{
	return $this->columns;
}
}
?>

 

Implementation looks like this:

// Initialize the grid control properties to be used to edit the records
	$Grid = new DataGrid('grdTable','tableName','primaryID',true,true,true,true,true,true);
	$Grid->AddColumn('AddressID','Address',true,'Address','Manage');
	$Grid->AddColumn('ContactInfoID','Contact',true,'Contact','Manage');
	$Grid->AddColumn('CourseName','Name');
	$Grid->AddColumn('CoursePar','Par');
	$Grid->Width 			= '100%';
	$Grid->ButtonType 		= 'image';
	$Grid->EditImageUrl 	= EDIT_ICON;
	$Grid->DeleteImageUrl 	= DELETE_ICON;
	$Grid->SaveImageUrl	 	= SAVE_ICON;
	$Grid->CancelImageUrl 	= CANCEL_ICON;
	$return .= $Grid->Display();

 

Obviously there are things missing... ignore the constants and the database methods, I have those proven to work in other areas of the application. Any help would be much appreciated!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.