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;
}
有帮助吗?

解决方案

$this is a predefined variable in PHP.

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

Change the var $this to something else.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top