PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hello everyone,
I'm new to PHP and used to code in Java. I tried the following but get a parser error for the "public $bla =..." line. X_Debug tells me: "Syntax Error: Expected: identifier, +, -". What is wrong?
Interestingly, I don't get an error message if I move the line beyond the class definition.
class Coordinate2D
{
public $x = 0;
public $y = 0;
}
class Paper
{
// paper dimension
const WIDTH_MM = 380;
const HEIGHT_MM = 290;
// 1 point = 2.83465669 mm
const MM_PER_POINT = 2.83465669;
public $bla = new Coordinate2D;
}
that's incorrect, defining constants in classes are done exactly as he's shown. You are using global constants, which are not related to OOP.
The problem is you can't use the 'new' keyword in a member definition. If you want to assign a new object instance to that member you'll have to do it in the constructor.
By the way, the error you should be seeing is something like "Parse error: syntax error, unexpected T_NEW in .. on line .." . please post the full error message in the future to make it easier for us to help you