将函数参数赋给变量时,PHP无法正常工作

将函数参数赋给变量时,PHP无法正常工作

问题描述:

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变量。 只要它是函数参数变量,就没有问题。 但是当我更改代码以将其分配到内部时,它不再有效(直接打开时空白页,AJAX响应内部服务器错误)。 函数内的其余代码使用变量$ this,并以第二种方式完美地工作。 p>

完整脚本是WordPress站点的AJAX电子邮件发件人,使用全局 $ wpdb。 p>

我错过了什么或者是否因为太晚才看到错误? :) p>

不工作 strong> p>

  function lookup_product($ in){
 $ this = $ in  ; 
 
 echo $ this; 
} 
  code>  pre> 
 
 

工作 strong> p>

  function lookup_product($ this){
 
 echo $ this; 
} 
  code>  pre> 
  div>

$this is a predefined variable in PHP.

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

Change the var $this to something else.