I'd like to know if there is an alternative to "this" and "super" from Java in PHP.

Greets, K?!

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!';
	}	
}

The super keyword, to my understanding would be used with this syntax in php

parent::someFunc();

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.

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();

Edited 6 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

This question has already been answered. Start a new discussion instead.