Which of the following heroes can tell my younger brother what is the return value of _ call () in php!
Source: Internet
Author: User
Which of the following heroes can tell me what is the return value of _ call () in php !~~ Classmy {public $ name = & quot; My Class & quot; function _ tostring () {return $ this-& gt; name. & quot; is an empty class & quot ;. which of the following heroes can tell me what is the return value of _ call () in php! ~~
Class my {
Public $ name = "My classes ";
Function _ tostring (){
Return $ this-> name. "is an empty class "."
";
}
Function _ call ($ n, $ v ){
Echo "nonexistent method:". $ n ."
";
Echo "error value:", print_r ($ v )."
"; // Output 1 at the end.
}
}
$ P = new my ();
Echo $ p;
$ P-> no ("first", 6, );
The following is the running result: my class is an empty class.
Method that does not exist: no
Error value: Array ([0] => first [1] => 6 [2] => a) 1
Why is there a 1 at the end ??? Puzzling !~~
------ Solution --------------------
Bool print_r (mixed expression [, bool return])
Return value of print_r
Function _ call ($ n, $ v ){
Echo "nonexistent method:". $ n ."
";
Print_r ($ v );
}
------ Solution --------------------
Return parameter. If this parameter is set to TRUE, print_r () does not print the result (this is the default action), but returns its output.
So we can do the same.
Echo "error value:". print_r ($ v, true )."
"; // Output 1 at the end.
------ Solution --------------------
This is not a problem with the _ call method. 1 is the return value of print_r.
Function _ call ($ n, $ v)
{
Echo "nonexistent method:". $ n ."
";
Echo "error value:"; print_r ($ v); // output 1 at the end.
}
So that 1 is not output.
Echo: ". print_r ($ v, true )."
"; In this way, the return value is output.
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.