echo value is different when that variable is passed in php
-
14-04-2021 - |
質問
I was working in php java bridge and came across this problem. The below is the code
$payID = $epaymentpipe->getPaymentId();
echo $payID;
the expected value is printed e.g., 5323423123
but when i pass the same variable in header like below, the object id is passing in payID.
header("location: URL?PaymentID=".$payID);
it is passing like http://URL?PaymentID=Object id #53
I Need to know whats happening here. When the variable is echoed its printing correctly but when i use the variable the object id is passing.
解決
header("location: URL?PaymentID=".$payID);
Use
header("location: URL?PaymentID=".((string)$payID));
and report this bug to the PHP developers.
The . operator should convert its arguments to a string using $object->__toString().
Note that this has been fixed in PHP 5.3 and above!
他のヒント
Cast the object as a string:
$payID = (string)$epaymentpipe->getPaymentId();
header("location: URL?PaymentID=".$payID);
The definition of echo is different as of that of print_r and var_dump, whenever any such thing happens check the value by dumping it through print_r or var_dump.