Jump to content

[SOLVED] Object functions inside curly brackets


gevans

Recommended Posts

Hey, just moved a clients site to a live environment for testing.

 

I'm getting this error - Parse error:  syntax error, unexpected '(', expecting '}' in ***/buildRelevantLinks.php on line 18

 

Bellow is line 18 - 20

$relevantLinks .= "<h4><a href=\"{$CN->output($details['href'])}\" title=\"{$CN->output($details['title'])}\">{$CN->output($details['title'])}</a></h4>
<p>{$CN->output($details['link_text'])}
</p>";

I'm assuming that the online environment doesn't like using curly brackets with functions/variables

 

Is there a setting in php.ini to allow this as I've used it a lot across about 7000 lines of code?

If the script was fine you wouldn't be getting a parse error.

 

Id be more inclined to break out of the string for something this complex. All complex variables (arrays and objects) need to be (well, should be) surrounded by curly braces{}. Method calls however should be escaped completely.

I think the parse error is there because the live server isn't supporting wrapping complex variables in curly brackets.

 

I've already broken away from the string to fix this problem. Just curious as to why two servers running PHP 5.0.* are doing different things with the same code. (code that isn't affected by php.ini)

If your code works on one server, but it generates a parse error like that on another server, then I will bet that you have some short open tags <? in it.

 

If so, please only use full opening tags <?php and <?php echo, because short open tags results in non-portable code and you won't always have the ability to turn on short open tags.

If your code works on one server, but it generates a parse error like that on another server, then I will bet that you have some short open tags <? in it.

 

If so, please only use full opening tags <?php and <?php echo, because short open tags results in non-portable code and you won't always have the ability to turn on short open tags.

 

Sorry to disappoint, my php is a little better than using short tags!! I do a lot of work for other companies as well as my own clients, test on a lot of different servers and versions of php.

 

Just can't get my head around this issue. Not a huge problem, just my preference and me being stuborn (just doesnt make sense).

There is no php.ini setting that affects how () or {} are treated. You may have a php installation that is broken or with a bug, but it is more likely that something in the lines of code immediately prior to the line where the error is being reported is causing the error, such as a HEREDOC tag out of place. Post at least 10 lines prior to the line where the error is reported.

 

It is also possible that your upload to the server failed and the file is not complete. Have you downloaded the file and examined it to make sure it is complete?

The file has been checked and double checked (re-uploaded to the live server). The only reason I didn't post more code is due to not questioning the full code itself. See bellow for the full code (function)

 

function buildRelevantLinks($parent_id){
global $root, $DB, $CN;
$query = "SELECT a.title, a.link_text, a.href
		FROM links a, relevant_links_ref b, relevant_links c
		WHERE b.p_id =$parent_id
		AND c.id = b.rl_id
		AND a.rl_id = c.id
		AND a.active =1";
$result = $DB->query($query);
if($DB->num_rows($result)>=1){
	$relevantLinks = "<div id=\"sub-nav-head\">
					<h2 class=\"main-title\">Relevant Links</h2>

				</div>
				<div id=\"right-content-body\">";
	while($details = $DB->fetch_array($result)){
		$relevantLinks .= "<h4><a href=\"{$CN->output($details['href'])}\" title=\"{$CN->output($details['title'])}\">{$CN->output($details['title'])}</a></h4>
					<p>{$CN->output($details['link_text'])}
					</p>";

	}
	$relevantLinks .= "</div>
				<div id=\"sub-nav-foot\"></div>";
} 
return $relevantLinks;
}

 

Also I can confidently say that there is no problem with the $DB or $CN objects. These are used across a number of sites and are fully tested.

I just copied and pasted that code in your last post and it got blown up with 5+ newlines at the end of each line. So, either the method you used to post it caused a problem (the "selectl" tag is missing above the window and I just tried to copy/paste code from a different thread and it worked) or there is something messed up in it that your editor is doing (which could account for the missing "select" tag.) If php is getting confused with bad characters at the end of lines, it could be causing that parse error.

 

Try making a new file and copy/paste the contents from the old file.

 

Are you uploading this to the live server using FTP in ASCII mode or binary mode?  It should be ASCII mode.

 

We can only help based on the information we see in your posts. You might have eliminated some possible reasons, but we don't know that and something you think is OK might actually be relevant to the problem. The members here have collectively seen 10's or 100's of thousands of posts. This is the first time I have seen your specific problem, so it is likely it is something that is present either in your file or on the server.

The select tag is missing because I used [ php] not [ code], code is re-posted bellow

 

<?php
function buildRelevantLinks($parent_id){
global $root, $DB, $CN;
$query = "SELECT a.title, a.link_text, a.href
		FROM links a, relevant_links_ref b, relevant_links c
		WHERE b.p_id =$parent_id
		AND c.id = b.rl_id
		AND a.rl_id = c.id
		AND a.active =1";
$result = $DB->query($query);
if($DB->num_rows($result)>=1){
	$relevantLinks = "<div id=\"sub-nav-head\">
					<h2 class=\"main-title\">Relevant Links</h2>

				</div>
				<div id=\"right-content-body\">";
	while($details = $DB->fetch_array($result)){
		$relevantLinks .= "<h4><a href=\"".$CN->output($details['href'])."\" title=\"".$CN->output($details['title'])."\">".$CN->output($details['title'])."</a></h4>
					<p>".$CN->output($details['link_text'])."
					</p>";

	}
	$relevantLinks .= "</div>
				<div id=\"sub-nav-foot\"></div>";
} 
return $relevantLinks;
}
?>

 

Transfer type is set to AUTO which defaults to ASCII from the host.

 

I've just made a new file uploaded it to the server in ASCII tested and same parse error. Downloaded the file and opened it (I use Notepad++) identical to the uploaded script

Ok, thanks for that.

 

I'll get the specific versions and have a look at the documentation on php.net

 

This site is going onto a shared server where I don't have control over the php installation, but I'll see what I can find

We can only help based on the information we see in your posts. You might have eliminated some possible reasons, but we don't know that and something you think is OK might actually be relevant to the problem.

 

Many Apologies (and a very embarrassed developer)  :'(

 

The shared servers I use require a htaccess file to specify what version of php to use, it defaults to php4.

 

Being ever the optimist about my own skills I messed up and forgot to upload the htaccess file on this new host account.

 

Again, many apologies.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.