name."是个空类".""; } function "/> name."是个空类".""; } function ">

Home  >  Article  >  Backend Development  >  哪位大侠可以告诉小弟我php中_call()的返回值是什么!

哪位大侠可以告诉小弟我php中_call()的返回值是什么!

WBOY
WBOYOriginal
2016-06-13 10:08:21814browse

哪位大侠可以告诉我php中__call()的返回值是什么!~~
class my{
public $name = "我的类";

function __tostring(){
return $this -> name."是个空类"."
";

}
function __call($n, $v){
echo "不存在的方法:".$n."
";
echo "错误的值:",print_r($v)."
"; //最后面输出1,是怎么回事。
}
}

$p = new my();

echo $p;

$p -> no("第一",6,a);



下面是运行结果:我的类是个空类
不存在的方法:no
错误的值:Array ( [0] => 第一 [1] => 6 [2] => a ) 1

为什么最后面会出现个1呢???百思不得其解!~~




------解决方案--------------------
bool print_r ( mixed expression [, bool return] )
print_r的返回值

function __call($n, $v){
echo "不存在的方法:".$n."
";
print_r($v); 
}
------解决方案--------------------
return 参数。若此参数设为 TRUE,print_r() 将不打印结果(此为默认动作),而是返回其输出
所以也可以这样

echo "错误的值:".print_r($v,true)."
"; //最后面输出1,是怎么回事。

------解决方案--------------------
你这个不是__call方法的问题,1是print_r的返回值
function __call($n, $v)
{
echo "不存在的方法:".$n."
";
echo "错误的值:";print_r($v); //最后面输出1,是怎么回事。
}
改成这样就不会输出1了。

你写成echo "错误的值:".print_r($v,true)."
"; 这样就会输出返回值

http://zhidao.baidu.com/question/256918769.html

http://cn2.php.net/print_r/


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn