-2

Situation:

Class A{
    public function F(){
        var_dump($this);
    }
}

A::F();

When doing this I get PHP Fatal error:Uncaught Error: Using $this when not in object context.

  1. Shouldn't I get a NULL or something, instead of the error?
  2. How do I check (in PHP 7.2!!!) if in object context?

Thx!

Alireza
  • 2,319
  • 2
  • 23
  • 35
Catalin
  • 773
  • 1
  • 7
  • 18
  • 4
    PHP allows calling non-static methods statically, but emits a warning. The real question is why are you calling this statically? – Devon Bessemer Aug 31 '18 at 14:57
  • 1
    Possible duplicate of [PHP Fatal error: Using $this when not in object context](https://stackoverflow.com/questions/2350937/php-fatal-error-using-this-when-not-in-object-context) – toesslab Aug 31 '18 at 15:34
  • Did you find the answer you were looking for? – Royal Wares Oct 19 '18 at 14:23

1 Answers1

0

$this is not available in static calls, you need to use self:: but keep in mind these are not interchangeable equivalents.

Royal Wares
  • 1,192
  • 10
  • 23