Which hero can tell my brother what is the return value of _call () in PHP?
Source: Internet
Author: User
Which hero can tell me what the return value of __call () in PHP is! ~~
Class my{
Public $name = "My Class";
function __tostring () {
Return $this, name. is an empty class "."
";
}
function __call ($n, $v) {
echo "Method not present:" $n. "
";
echo "error value:", Print_r ($v). "
"; The last side output 1, what is going on.
}
}
$p = new My ();
Echo $p;
$p-No ("first", 6,a);
Here is the result of the run: My class is an empty class
Non-existent method: No
Error value: Array ([0] = = First [1] = 6 [2] + a) 1
Why is there a 1 on the last side??? The solution is not to be thought of! ~~
------Solution--------------------
BOOL Print_r (mixed expression [, bool return])
return value of Print_r
function __call ($n, $v) {
echo "Method not present:" $n. "
";
Print_r ($v);
}
------Solution--------------------
Return parameter. If this parameter is set to True,print_r () will not print the result (this is the default action), but instead return its output
So you can do it.
echo "error value:". Print_r ($v, true). "
"; The last side output 1, what is going on.
------Solution--------------------
You're not the __call method, 1 is the return value of Print_r.
function __call ($n, $v)
{
echo "Method not present:" $n. "
";
echo "error value:";p rint_r ($v); The last side output 1, what is going on.
}
Change it so that it doesn't output 1.
You write the echo "wrong value:". Print_r ($v, true). "
"; This will output the return value
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.