如何获取对象的详细信息


How to get the details of an object

使用以下代码:

$fh = fopen('log.txt', 'w') or die("Can't open file.");
// output the value as a variable by setting the 2nd parameter to true
$results = print_r($_REQUEST['lat'], true);
fwrite($fh, $results);
fclose($fh);

我正在尝试输出传入的对象及其引用。入站对象是

$_REQUEST['lat'];

但当我最终打印出来时,我得到的只是:

[object Object]

我尝试了多种方法来获取对象的数据,但都不起作用。我在这里错过了什么?

当我只使用print_r函数运行$_REQUEST时,我得到的是:

Array
(
    [lat] => [object Object]
    [long] => [object Object]
)

字符串[object Object]javascript中对象的默认字符串表示。看起来您正试图从javascript(ajax?)向php代码发送请求,而不是发送数据,而是发送对象。

如果你有这样的东西:

$.ajax({
    url: "page.php", 
    data: {'lat' : $('#input_element') }
    success: function(result){
        ...
    }
});

你实际上应该这样做:

$.ajax({
    url: "page.php", 
    data: {'lat' : $('#input_element').val() }
    success: function(result){
        ...
    }
});