显示从php脚本返回

显示从php脚本返回,php,Php,我有这个剧本: /** Key */ private $k = 't0kJKx27zm4ronxqXe'; /** Private salt */ private $p = 't0kez47ARpOxFnoVNJ'; private $host = 'http://url.com'; public function __construct() { ; } public function generateUrl($iniciator = NULL) { $token =

我有这个剧本:
/** Key */
private $k = 't0kJKx27zm4ronxqXe';

/** Private salt */
private $p = 't0kez47ARpOxFnoVNJ';

private $host = 'http://url.com';

public function __construct() 
{
   ;
}


public function generateUrl($iniciator = NULL)
{
    $token = hash_hmac('sha1', date('Y-m-d') . $this->k, $this->p);

    if($iniciator !== NULL)
    {
        if(!is_string($iniciator))
        {
            throw new \Exception('Iniciator must be string!');
        }
    }

    return $this->host . 'a=' . $this->a . '&k=' . $token . '&u=' . $iniciator;

}
}
如何回显/打印。。。作为回报的字符串?

返回$this->host'a='$这个->一个&k='$代币。”&u='$罪犯


您的代码不完整,缺少第一行,例如:

class Test {
然后,您可以使用以下命令运行代码:

$someVar = new Test;
echo $someVar->generateUrl();
$someVar = new Test;
$someVar->generateUrl(); // no need for echo because it's already in class
如果要从类中打印,只需编写echo而不是return:

echo $this->host . 'a=' . $this->a . '&k=' . $token . '&u=' . $iniciator;
然后,您可以使用以下命令运行代码:

$someVar = new Test;
echo $someVar->generateUrl();
$someVar = new Test;
$someVar->generateUrl(); // no need for echo because it's already in class
警告:您尚未定义变量$a作为回报。

$class=new YourClassName;echo$class->generateUrl;我想是吧。回声发生器;。