【问题标题】:Variable access in method of class类方法中的变量访问
【发布时间】:2013-09-08 10:06:02
【问题描述】:

我已经列出了代码:

class myClass {

public $url;
public $content;
public $ip;

public function analysis()
{       
    $list = array('http://site.ru?url=http://'.urlencode($this->url) => 'get_tcy');

    function request_callback($response, $info, $request)
    {
        //at this place I need print content of $list variable
    }

    $rc = new RollingCurl("request_callback");
    foreach ($list as $key => $value) 
    {
        $request = new RollingCurlRequest($key);
        $rc->add($request);
    }
    $rc->execute();
}

但我在打印变量内容时遇到问题。 如何在需要的地方打印?

【问题讨论】:

  • 又不能作为参数传给request_callback()
  • 你为什么不能这样做?
  • 它是一个特定的类并使用回调函数

标签: php variables


【解决方案1】:

我想这就是你需要的

$fn = function ($response, $info, $request) use ($list) {
    var_dump($list);
};
$rc = new RollingCurl($fn);

更多信息here

【讨论】:

  • 那些代码语法不正确。不可能使用正确的形式。我需要其他解决方案。
猜你喜欢
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-22
  • 1970-01-01
  • 1970-01-01
  • 2011-12-10
  • 1970-01-01
相关资源
最近更新 更多