Using $this when not in object context

From Php

Jump to: navigation, search

You can get error messages like this:

  Using $this when not in object context in foo.php on line 6

if you use $this outside of a class.

Note that you were allowed to use $this outside of classes in PHP4, but PHP5 does not allow it.

WRONG

 $this->foo=7;  // not legal outside of a class


RIGHT

 class Foo
 {
   function foo()
   {
      $this->foo=7;  // legal inside a class
   }
 }
Personal tools