PDA

View Full Version : Why is this line giving me a parse error?


mothra
08-16-2004, 09:18 PM
I'm trying to use the mathmatical equivalent of PI for accuracy, here is the offending line, somebody please tell me where I went wrong..

var $PI = 4 * atan(1);

Parse error: parse error, expecting `','' or `';''

hemebond
08-16-2004, 10:33 PM
What is the previous line?

mothra
08-16-2004, 10:36 PM
The previous line is:

var $left=10;

The problem is def. w/ the line I posted. If i just do: var $PI = 3.141 ...it works fine.

mordred
08-17-2004, 12:21 AM
Your problem is that PHP does only allow constant values to be used as initialization of class members. You use an expression, the result from a mathematical calculation. That's unfortunately not allowed. From the manual (http://us2.php.net/manual/en/language.oop.php):


In PHP 4, only constant initializers for var variables are allowed. To initialize variables with non-constant values, you need an initialization function which is called automatically when an object is being constructed from the class. Such a function is called a constructor (see below).


Follow this advice, it's common practice.

mothra
08-18-2004, 04:53 PM
Thanks Mordred, that makes sense. I'm still new to PHP all my OO background (if you can call it that) is from VB. So I probably should have figured out what the prob. was, as usual the manual has the answers...