Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 21st, 2003, 08:04 PM
Authorized User
 
Join Date: Dec 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default IF parse error

I have a parse error and I can't figure what's wrong. i assume its a syntax error but I just don't see it. Here's the error:

Parse error: parse error, unexpected T_IF, expecting ',' or ';' in C:\Program Files\Abyss Web Server\htdocs\phpdemo\stereo2.php on line 10

Here's my code:

<?

function sex2Dec() {

// SEXAGESIMAL TO DECIMAL
//declare variables to be available inside of function
global $AString, $A1, $A2, $A3, $R1

//save sign
if ($AString < 0) {
    $Sign = -1;
    }

if ($AString > 0) {
    $Sign = 1;
    }

$A1=abs($AString);

//calculate??
$A=$Sign*($A1+$A2/60+$A3/3600);
return($A);

}

//start of code
$T = sex2Dec()*15*$R1-$Lat;

?>

Line 10 is in the middle of the if statement but it looks okay to me. Can any one see what I am doing wrong?

Thanks!

 
Old December 21st, 2003, 08:52 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

This line is missing a semi-colon:

global $AString, $A1, $A2, $A3, $R1

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old December 22nd, 2003, 12:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Food for thought -- $Sign is never initialized if $AString is equal to zero. This will cause a NOTICE level warning on PHP installations where error_reporting is set to report these warnings. (E_ALL, the default setting, would complain about this).

Suggested replacement: how about this?

$Sign = ($AString < 0)? -1 : 1;


Also, it's not really good programming style to have a function only operate on global variables. It totally limits the usefulness of the function because you can't just use it in another application. You should pass all the data to the function as parameters.

Finally, you create a variable, $A, to hold the result of your calculations, but all you do with $A is return it. It makes more sense to NOT create the variable and just return the result of the calculation directly. It's a little more streamlined, since you don't have to allocate memory for a variable that you're just going to free up anyway.

  return $Sign * ($A1 + $A2/60 + $A3/3600);


Take care,

Nik
http://www.bigaction.org/
 
Old December 29th, 2003, 09:31 AM
Authorized User
 
Join Date: Dec 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Missing semi-colon! Typical, thanks for pointing it out.

Thanks for the ideas, I'll try to work them in.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: syntax error, unexpected T_ELSE in /h vipin k varghese BOOK: XSLT Programmer's Reference, 2nd Edition 4 September 29th, 2011 01:19 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM
PHP Parse error: parse error, unexpected T_STRING geminient PHP How-To 4 August 18th, 2007 02:27 AM
Parse error: parse error, unexpected $end Ayodeji Adegbaju Pro PHP 3 January 12th, 2007 12:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.