PDA

View Full Version : Instantiating Object Variables


nerhael
05-20-2003, 05:29 PM
Okay, first question:

Can an object have a static constant like in Java?

Second:

Can you instantiate an object variable to something outside of the constructor? So that when you create the object, with an empty constructor method, it might already have default values?

Thinking about this, I think my first question is more what I want. I want to be able to find the value of a variable in an object when all I have is it's classname.

Pete.

mordred
05-20-2003, 09:45 PM
That's not possible with PHP, at least not in the same manner as it is done in Java.

You can of course set a default value for a class variable outside of the constructor, but unless there's actually an object created from the class, you'll have to use a hack that uses get_class_vars() which returns an array of a class variables.