Question

I have a problem which is really brain-cracking. I would like to use the $this variable inside a function. As long as it is the function parameter variable, there is no problem. But when I change the code to assign it inside, it is no longer working (blank page when direct opened, AJAX responds with Internal Server Error). The rest of the code inside the function uses the variable $this, and perfectly works in the second way.

The full script is an AJAX e-mail sender for a WordPress site, using global $wpdb.

Am i missing something or is it too late night to see the mistake? :)

NOT WORKING

function lookup_product($in){
    $this = $in;

    echo $this;
}

WORKING

function lookup_product($this){

    echo $this;
}
Was it helpful?

Solution

$this is a predefined variable in PHP.

http://php.net/manual/en/language.oop5.basic.php

Change the var $this to something else.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top