PHP 5, object living time, private, protected
Posted: Tue Jul 22, 2003 12:49 pm
Hi!
I'm currently developing a set of classes that will be used in the future with PHP 5. I don't have to worry about PHP 4.x compatibility. Now, I've fooled around and there are some things that bug me.
First of all, how long will an instance of a class live? (If it is done like I think then it will die when it is unset or script ends.) If script ends, is the __destruct function always ran or do I have to unset them manually in order to be sure?
Then the other question, what's the difference between private and protected? (If the same as with java then it is so that private methods can't be accessed from child that extends the parent, while protected can be?)
Third
If I do this:
am I accessing the same variable in addOne and __construct, and is the number unset correctly in __destruct?
Also, is a static funtion of any use? (Example please?)
There isn't much info about PHP 5 oop yet, so I've read some Java tutorials. Hopefully somebody here knows. I also feel that the majority of PHP programmers are about to find the wonders of oop, or have just recently, so there should be a big need for PHP oop tutorial. (A proper one, with explanation of the things that I ask above and more, like throw try catch etc. essential)
Thanks,
99
I'm currently developing a set of classes that will be used in the future with PHP 5. I don't have to worry about PHP 4.x compatibility. Now, I've fooled around and there are some things that bug me.
First of all, how long will an instance of a class live? (If it is done like I think then it will die when it is unset or script ends.) If script ends, is the __destruct function always ran or do I have to unset them manually in order to be sure?
Then the other question, what's the difference between private and protected? (If the same as with java then it is so that private methods can't be accessed from child that extends the parent, while protected can be?)
Third
If I do this:
Code: Select all
class test{
private $number;
function __construct(){
$this->number=0;
}
function addOne(){
$number++;
}
function getNumber(){
return $this->number;
}
function __destruct(){
unset($this->number);
}
}Also, is a static funtion of any use? (Example please?)
There isn't much info about PHP 5 oop yet, so I've read some Java tutorials. Hopefully somebody here knows. I also feel that the majority of PHP programmers are about to find the wonders of oop, or have just recently, so there should be a big need for PHP oop tutorial. (A proper one, with explanation of the things that I ask above and more, like throw try catch etc. essential)
Thanks,
99