打印(_r);不要归还任何东西;var_dump显示NULL


Print_r doesn't return anything; var_dump shows NULL

我是web开发的新手,正在尝试Braintree webhook。我正在使用他们的创建潜水器示例代码来创建潜水器,然后应该会有一个通知到达我的服务器,告诉我它是否成功。

我的方法:我刷新了submarchant.php页面(我在NameCheap服务器上使用Wordpress),然后echo的"成功!"。然后我转到webhooks.php页面并刷新它。然而,var_dump只返回NULL NULLprint_r不返回任何内容。为什么print_r没有显示任何内容?

submarchant.php-当我设置$one = 1并为潜水器设置新的id时,这会创建潜水器

<?php
require_once(__DIR__ . '/../braintree/lib/Braintree.php');
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('A');
Braintree_Configuration::publicKey('B');
Braintree_Configuration::privateKey('C');
 function fd_create_sm() {
    $one;
    $one = 1;
    if($one=1) {
    $merchantAccountParams = [
      'individual' => [
        'firstName' => 'Janez',
        'lastName' => 'Doe',
        'email' => 'jane@14ladders.com',
        'phone' => '5553334444',
        'dateOfBirth' => '1981-11-19',
        'ssn' => '456-45-4567',
        'address' => [
          'streetAddress' => '111 Main St',
          'locality' => 'Chicago',
          'region' => 'IL',
          'postalCode' => '60622'
        ]
      ],
      'business' => [
        'legalName' => 'Jane''s Ladders',
        'dbaName' => 'Jane''s Ladders',
        'taxId' => '98-7654321',
        'address' => [
          'streetAddress' => '111 Main St',
          'locality' => 'Chicago',
          'region' => 'IL',
          'postalCode' => '60622'
        ]
      ],
      'funding' => [
        'descriptor' => 'Red Ladders',
        'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK,
        'email' => 'funding@blueladders.com',
        'mobilePhone' => '5555555555',
        'accountNumber' => '1123581321',
        'routingNumber' => '071101307'
      ],
      'tosAccepted' => true,
      'masterMerchantAccountId' => "na",
      'id' => "green_ladders"
    ];
    $result = Braintree_MerchantAccount::create($merchantAccountParams);
    $result->success;
    if($result->success) {
    echo 'Success!';
    } else {
    print_r($result->errors);
            $errordata;
            echo '***********';
            $BT_Errors = new Braintree_Error_ErrorCollection($errordata);
            echo '***********';
            $BT_Errors->deepAll();
            echo '***********';
            $BT_Errors->onHtmlField("transaction[amount]");
    }
    $result->merchantAccount->status;
    $result->merchantAccount->id;
    // "blue_ladders_store"
    $result->merchantAccount->masterMerchantAccount->id;
    // "14ladders_marketplace"
    $result->merchantAccount->masterMerchantAccount->status;
    // "active"
    } else {
    return;
    }
 }
fd_create_sm();
?>

webhooks.php

<?php
var_dump($_POST['bt_signature']);
var_dump($_POST['bt_payload']);
print_r($_POST['bt_signature']);
print_r($_POST['bt_payload']);
?>

输出的数据很可能存储在某个输出缓冲区中。如果您非常确定要以这种方式调试代码,请尝试在使用print_r输出数据后立即添加wp_die();调用。这应该会有所帮助!

还有一件事:有时由于数据流更复杂,一些代码(不是这种特殊情况)实际上永远不会输出。对于这种情况,最好使用一些第三方调试工具,或者,如果您正在寻找更简单的解决方案,可以将一些输出写入某个日志文件,然后检查该文件。

祝你好运!

print_r() 的最后一行之后添加die;