...

View Full Version : syntax error, unexpected ','



jarv
05-24-2011, 12:46 PM
Can someone help please and explain what I am doing wrong?




$month=date("F",strtotime($dateStart));

if($month == "March"){
if($dateStart == strtotime($month),'last sunday of this month'){
$GMT = "+01"
}

}

tangoforce
05-24-2011, 01:32 PM
Having reformatted your code to that which is in the coding styles link in my sig, it's immediately obvious whats gone wrong - look:



<?
$month=date("F",strtotime($dateStart));//Ok

if($month == "March")//Ok
{
if($dateStart == strtotime($month),'last sunday of this month')//Not Ok *
{
$GMT = "+01"//No semicolon ;
}

}
?>

*This line will not work. You're converting a string to a timestamp and then closing the function whilst outside of the function trying to use 'last sunday of..' and then include that mix into an IF comparison.

I think what you were trying to achieve is this:


if($dateStart == strtotime($month,'last sunday of this month'))


This doesn't work either. If you look at strtotime (http://uk2.php.net/strtotime) in the php manual you will see that you can only use a relative time string for the first parameter not the second which expects a timestamp.

You need to take another look at the manual and rewrite your code.

Inigoesdr
05-25-2011, 12:32 AM
That's some crazy indenting, tango. :)

tangoforce
05-25-2011, 02:06 AM
Ah, but its much easier to understand all the code, find $end errors etc ;)

You should try it!

Inigoesdr
05-25-2011, 06:05 AM
No, thanks. I prefer this format:


<?
$month = date("F",strtotime($dateStart));//Ok

if($month == "March")//Ok
{
if($dateStart == strtotime($month),'last sunday of this month')//Not Ok *
{
$GMT = "+01"//No semicolon ;
}
}
?>

That's much easier to read to me.

tangoforce
05-25-2011, 12:55 PM
In my mind thats pretty much the same thing - the { and } are on their own lines instead of the { being at the end of the opening line.

The only difference is that i found it easier to have the opening lines indentation normal and then the actual block of code indented as it may or may not run with the main code unlike the opening line (the if statement) which will always run.

MattF
05-25-2011, 01:10 PM
In my mind thats pretty much the same thing - the { and } are on their own lines instead of the { being at the end of the opening line.

I'm with Inigo' on this one. Your layout is better than some, but the layout example he posted is by far the easiest to follow when you're scanning through lots of code. There's no guessing as to which follows what at all, which is why I use the generally same method as him.

tangoforce
05-25-2011, 01:24 PM
Hi Matt

It's odd because the complete opposite is true at sitepoint - where they all prefer the opening { at the end of the same line (whoever thought that would work?) and the the closing brace on its own line at the far left (even with others above and below it). I never liked that and found it very annoying to debug and fix $end errors etc.

Very strange, this forum actually seems to have far superior programmers and sitepoint seems to be the glossy well publicised site yet they do things so weirdly..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum