Hello,
Can someone please help me out? I know that using variables in a class script is a good programming practice but that they are also not required. I want to do things the correct way so I figured I would ask.
For a while I was declaring all of my vars at the top of the script like:
[PHP]
var $myvar;
var $mysecondvar;
...
[/PHP]
I would leave the () blank in ALL of my methods and just assign the var in the script where I instantiated the object like so:
[PHP]
$something = new something();
$something->myvar = 'dsfsfjlk';
$something->mysecondvar = 'dafkad';
[/PHP]
After looking at a completed script, I am looking at a lot of lines that reference those public vars and now want to know why couldn't I just declare the vars within the parenthesis and NOT declare them as above?
What is the difference here? I mean, if I have a variable that will be global inside the class, I can see declaring the vars outside of the parenthesis but short of that, it seems to me that I should be placing the vars within the parenthesis. Am I correct?
Is there a rule about this somewhere I missed?
Thanks,
Frank
Can someone please help me out? I know that using variables in a class script is a good programming practice but that they are also not required. I want to do things the correct way so I figured I would ask.
For a while I was declaring all of my vars at the top of the script like:
[PHP]
var $myvar;
var $mysecondvar;
...
[/PHP]
I would leave the () blank in ALL of my methods and just assign the var in the script where I instantiated the object like so:
[PHP]
$something = new something();
$something->myvar = 'dsfsfjlk';
$something->mysecondvar = 'dafkad';
[/PHP]
After looking at a completed script, I am looking at a lot of lines that reference those public vars and now want to know why couldn't I just declare the vars within the parenthesis and NOT declare them as above?
What is the difference here? I mean, if I have a variable that will be global inside the class, I can see declaring the vars outside of the parenthesis but short of that, it seems to me that I should be placing the vars within the parenthesis. Am I correct?
Is there a rule about this somewhere I missed?
Thanks,
Frank
Comment