Unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}'

IerardiMario

Nuovo Utente
19 Ott 2011
7
0
0
Problema con definizione di una proprietà

Il codice qui sotto mi genera questo errore:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /membri/marioierardi/engine.php on line 100
Ho controllato un sacco di volte ma non capisco dove ho sbagliato.
Ho provato a spostare le proprietà dopo i metodi e lo stesso errore si verifica sul primo metodo dopo il costruttore.
Help!

PHP:
<?php
	include_once 'engine_resources/codes.php';
	$pagePath = verifyRequest();
	$page = new Page($pagePath);
	
	function verifyFirstLevelRequest($path)
	{
		$firstLevPath = $path;
		/*Concateno con la cartella e procedo a verifica*/
		
		foreach($_GET as $key=>$index)
		{
			if(is_dir($firstLevPath.$key)!==FALSE)
			{	
				$firstLevPath.=$key;
			}
		}
		
		if($firstLevPath==$path)
		{
			return REQUESTED_INEXISTENT_PAGE;/*La cartella non esiste per il percorso specificato*/
		}
		
		return verifyPageTree($firstLevPath);
	}
	
	function verifySecondLevelRequest($path)
	{
		$secondLevelPath = "";
		if(($firstLevelPath = verifyFirstLevelRequest($path))!=FALSE)
		{
			/*Concateno con la sottocartella e procedo a verifica*/
			$subDir = $firstLevelPath;
			str_replace($path,'',$subDir);/*Cancella il percorso lasciando solo il nome*/
			$secondLevelPath.=$firstLevelPath.'/'.$_GET[$subDir];
			
			if(!is_dir($secondLevelPath))
			{
				return REQUESTED_INEXISTENT_PAGE;/*La cartella non esiste per il percorso specificato*/
			}
			
			return verifyPageTree($secondLevelPath);
		}
	}
	
	function verifyPageTree($path)
	{
		/*Verifica basilare di integrità dell'albero della pagina richiesta*/
		
		$childrenRequired = array("/subpages/","content.php","include_apps","meta","style.css");
		
		$pagePath = $path;
		if(($pageResorce = opendir($pagePath))!==FALSE)
		{
			$childrenExisting = array();
			while(($subFile = readdir($pageResorce)) !== FALSE)
			{
				array_push($childrenExisting,$subFile);
			}
			closedir();
			
			if($childrenRequired==$childrenExisting)
			{
				/*Integrità confermata*/
				return pagePath;
			}else{
				return REQUESTED_INEXISTENT_PAGE;/*Integrità non confermata*/
			}
		}else{
			return REQUESTED_INEXISTENT_PAGE;/*Cartella inaccessibile*/
		}
	}
	
	function verifyRequest()
	{
		$pagesPath = $_SERVER['DOCUMENT_ROOT'].'/pages/';
		
		if($_SERVER['REQUEST_METHOD'] == 'GET')
		{
			$sog=sizeof($_GET);
			if($sog>1)
			{
				return REQUESTED_INEXISTENT_PAGE;
			}elseif($sog==1)
			{
				if(empty($_GET[0]))
				{
					return verifyFirstLevelRequest($pagesPath);
				}else
				{
					return verifySecondLevelRequest($pagesPath);
				}
			}
		}else{
			return REQUESTED_DEFAULT_PAGE;
		}
	}
	
	class Page{	
		private $path;
		private $meta;
		private $headerApps;
		private $bodyApps;
		private $css;
		private $subPagesReferences = array();/*Carichiamo solo alcuni dati, utili alla navigazione, delle sottocategorie della pagina*/
	
		function __construct($requestSubject){
			$this->parseRequest($requestSubject); /*Fatto*/
			$this->getCSS();
			$this->getMeta(); /*Fatto*/
			$this->getApps(); /*Fatto*/
			$this->getSubPagesRef();
		}
		
		private function getMeta(){
			$rawData = $this->getByFile($this->path.'meta');
			$metalist = explode(';',$rawData);
			foreach($metalist as $value)
			{
				$tmp = explode('=',$value);
				$formatted = '<meta name="'.$tmp[0].'" content="'.$tmp[1].'"/>';
				$this->meta.=$formatted;
			}		
		}
		
		private function getApps(){
			$localApps = $this->getLocalApps();
			$formatted='';
			$rawData = $this->getByFile($this->path.'include_apps');
			$applist = explode(';',$rawData);
			foreach($applist as $value)
			{
				if(substr($value,0,11)=='external://')
				{
					$formatted = '<script language="javascript" type="text/javascript" src="'.substr($value,11).'"></script>';
					$headerApps.=$formatted;/*I link esterni evngono messi per default nella testata*/
				}else{
					if(($appIndex = array_search($value, $localApps)) != FALSE)
					{
						$formatted = '<script language="javascript" type="text/javascript" src="'.$localApps[0].$localApps[1].'"></script>';
						if($localApps[0]=='/apps/head/')
						{
							$headerApps.=$formatted;
						}else{
							$bodyApps.=$formatted;
						}
					}
				}
			}
		}
		
		private function getLocalApps(){
			$localAppList = array();
			$bodyAppPath = 'apps/body/';
			$headAppPath = 'apps/head/';
			$pageResorce = opendir($bodyAppPath) or die('impossibile aprire la cartella!');
			while(($file = readdir($pageResorce)) !== FALSE)
			{
				array_push($localAppList,array($file,$bodyAppPath));
			}
			closedir();
			$pageResorce = opendir($headAppPath) or die('impossibile aprire la cartella!');
			while(($file = readdir($pageResorce)) !== FALSE)
			{
				array_push($localAppList,array($headAppPath,$file));
			}
			closedir();
			return $localAppList;
		}
		
		private function getCSS(){
			
		}
		
		private function getSubPagesRef(){
			
		}
		
		private function parseRequest($subject){
			$requestPath = $subject;
			if($requestPath==REQUESTED_DEFAULT_PAGE)
			{	
				$requestPath=$_SERVER['DOCUMENT_ROOT'].'/pages/home/';
			}elseif($requestPath==REQUESTED_INEXISTENT_PAGE)
			{
				$requestPath=$_SERVER['DOCUMENT_ROOT'].'/pages/pagenotfound/';
			}
			
			$this->path=$requestPath;
		}
		
		private function getByFile($path){
			$text = "";
			$fp = fopen($path,'r') or die('Impossibile aprire il file!');
			
			while(($line = fgets($fp))!== FALSE)
			{
				$text.=$line;
			}
			return $text;
		}
		
		function printDocTitle(){
			print "Mio titolo";
		}
		
		function printMetaTags(){
			print $this->meta;
		}
		
		function printHeaderApps(){
			print $this->headerApps;
		}
		
		function printCSS(){
			print $this->css;
		}
		
		function printBodyHeader(){
			include_once 'shared_content/header.php';
		}
		
		function printBodyContent(){
			include_once $this->path.'/content.php';
		}
		
		function printBodyFooter(){
			include_once 'shared_content/footer.php';
		}
		
		function printBodyApps(){
			print $this->bodyApps;
		}		
	};
?>
 
Ultima modifica:

IerardiMario

Nuovo Utente
19 Ott 2011
7
0
0
ciao
sarebbe bene che tu indicassi quale è la riga 100, poi verifica le righe prima spesso gli errori segnalati nascono a monte

grazie per aver risposto. la riga 100 e quella contenente la prima proprietà della classe Page: "private $path;"
ho ricontrollato... non riesco a trovare errori. del resto sono alle prime armi e potrei ignorare qualcosa di banale.
 

IerardiMario

Nuovo Utente
19 Ott 2011
7
0
0
Ho provato e a me funziona correttamente... Sei sicuro che l'errore sia lì?
Grazie per la risposta.
Sicuro. Lo sai la cosa ancora più strana è che l'errore si verifica al momento del test sul dominio altervista e non in locale con EasyPHP5.4.
Non potrebbe essere un problema di versione presente su altervista?
 

IerardiMario

Nuovo Utente
19 Ott 2011
7
0
0
RISOLTO!
Era la versione di php su altervista: 4.4.9
Modo per risolverla:
accedere alle impostazioni del file .htaccess (presente all'interno della sezione 'gesione file' del proprio pannello di controllo) e tra le opzioni disponibili modificare:
"Scegli la versione di PHP da usare" portando "Attiva supporto php5 (off = php4)" da off a on.
Grazie a todos e alla prossima!

P.S.
per l'appunto, mi è stato detto che in php 4 il cotruttore devono avere il nome della classe e non ci sono private e public
 
Ultima modifica:

alessandro1997

Utente Attivo
6 Ott 2009
5.302
1
0
26
Roma
alessandro1997.netsons.org
Togli pure il forse. È sicuramente un problema di Altervista. A meno che non specifichi diversamente nel file .htaccess il tuo sito girerà su PHP 4, che non consente la definizione della visibilità dei membri di una classe (puoi usare solo var, ma non public, protected o private).
Per risolvere devi creare un file .htaccess e, tramite l'editor di Altervista, abilitare PHP 5.
 
Discussioni simili
Autore Titolo Forum Risposte Data
W Parse error: syntax error, unexpected '$result' (T_VARIABLE) PHP 4
B Errore unexpected '$variabile' (T_VARIABLE) in your code on line PHP 2
G unexpected '$conn' (T_VARIABLE) PHP 2
N [PHP] ERRORE: SyntaxError: Unexpected token N in JSON at position 1 PHP 0
G [WordPress] [PHP] Parse error: syntax error, unexpected '$x332cbce1' WordPress 2
T [PHP] errore unexpected T_LNUMBER che non so interpretare PHP 6
U [PHP] Parse error: syntax error, unexpected variabile (T_VARIABLE) PHP 8
ANDREA20 [PHP] syntax error, unexpected PHP 4
ANDREA20 [PHP] syntax error, unexpected T_ELSE [era]urgentissimo] PHP 15
A [PHP] syntax error, unexpected T_STRING su html PHP 11
R Aiuto: Uncaught SyntaxError: Unexpected token WordPress 2
G Parse error: syntax error, unexpected '=' PHP 2
gandalf1959 Parse error: syntax error, unexpected T_VARIABLE PHP 2
Z Parse error: syntax error, unexpected 'parts' (T_STRING), expecting ',' or ';' PHP 2
O unexpected 'â' PHP 4
G Uncaught SyntaxError: Unexpected token ILLEGAL Javascript 1
T Nuova installazione vB: Parse error: syntax error, unexpected T_STRING ... CMS (Content Management System) 0
K Parse error: syntax error, unexpected $end PHP 2
H Parse error: syntax error, unexpected T_SL in /membri/sito/pagina.php... PHP 2
M parse error:syntax error,unexpected T_STRING PHP 2
L syntax error, unexpected T_VARIABLE ??? PHP 1
P Parse error: syntax error, unexpected T_STRING on line 5 PHP 7
J Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in PHP 3
N Parse error: syntax error, unexpected T_VARIABLE Piccolo Aiutino :) PHP 0
L Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' PHP 1
M Errore unexpected T_VARIABLE PHP 0
M [PHP] query string PHP 2
V [PHP] Preg Match e Uninitialized string offset PHP 4
O [PHP] CSV String o no? PHP 2
R how to save into a string an array of values passed used $POST PHP 0
P Query string PHP 6
M replace string con jquery jQuery 1
felino [C#] String format: qualche dubbio! C/C++ 1
felino [C#] da Lista a string[] .NET Framework 1
M Message could not be sent. Mailer Error: Language string failed to load: Authentication failed PHP 2
T string split...da java a php PHP 2
O Modificare query string senza refresh di pagina PHP 7
C cast da int o double in String Java 2

Discussioni simili