Php's alternative to Java's "this" and "super"
I'd like to know if there is an alternative to "this" and "super" from Java in PHP.
Greets, K?!
K?!
Junior Poster in Training
95 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
This is supported in php. I'm not to sure if the keyword super is. Here's a simple example of this:
class Human
{
public $thirsty = 'Very thirsty!';
function drink($water)
{
$this->thirsty = 'Not thirsty!';
}
}
buddylee17
Practically a Master Poster
697 posts since Nov 2007
Reputation Points: 232
Solved Threads: 137
The super keyword, to my understanding would be used with this syntax in php
parent::someFunc();
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
Thank you :-).
Greets, K?!
Edit: Synking, i don't know if javascript uses this and super, but i meant java.
"This" and "super" are used to another variable then the one you would use normally. For example, when you have 3 variables with the same name in a superclass, a class an a function of the class, "super" will refer to the variable in the superclass, "this" will refer to the variable in the class, and use of none will refer to the closest variable, in this case the one in the function itself.
K?!
Junior Poster in Training
95 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
php uses the keyword this but does not use super. also, parent::method() works like super().method(). When accessing any methods or variables for php inside of the class you must reference using the this keyword as such
class test{
public $var
public function tester($x){
$this->var=$x;
}
}
when accessing methods or variables outside the class you must also use -> instead of . so in java you would use
test var=new test();
var.tester();
php would be
$var= new test();
$var->tester();
wrivera
Junior Poster in Training
53 posts since Jan 2010
Reputation Points: 10
Solved Threads: 10