Jump to content

What is var $this?


terryds

Recommended Posts

It is special variable, instance variable. It does reprerents the object itself when used inside object context.

Link to comment
Share on other sites

See my code..

<?phpfunction bark() {    print "{$this->Name} says Woof!\n";} bark();

The error appears : Fatal error: Using $this when not in object context in C:\xampp\htdocs\terrytest\scratches\$this.php on line 3I get the code from http://www.tuxradar.com/practicalphp/6/5/0 Can you tell me how to fix it? Or give me another simple example of using $this ? I still don't understand about it

Link to comment
Share on other sites

$this->name tells to get 'name' property of current object. You neither have any class defined nor it have any property. You need to define a class first. Only class methods can resolve $this, functions can not.

Link to comment
Share on other sites

See my code..
<?phpfunction bark() {	print "{$this->Name} says Woof!\n";} bark();

The error appears : Fatal error: Using $this when not in object context in C:\xampp\htdocs\terrytest\scratches\$this.php on line 3I get the code from http://www.tuxradar....cticalphp/6/5/0 Can you tell me how to fix it? Or give me another simple example of using $this ? I still don't understand about it

the previous chapter setup the proper context for the current examplehttp://www.tuxradar.com/practicalphp/6/4/0
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...