douzheng0702 2012-09-14 04:59
浏览 43
已采纳

任何人都可以帮我解决错误:::解析错误:语法错误,第14行/localhost/braintree/app.php中的意外T_FUNCTION

<?php

require_once 'braintree-php-2.14.0/lib/Braintree.php';
require_once __DIR__ . 'silex/vendor/autoload.php';
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('...');
Braintree_Configuration::publicKey('...');
Braintree_Configuration::privateKey('...');
$app = new Silex\Application();
$app->get('/', function () {
    include 'views/form.php';
});
$app->run();
//$app->get("/braintree-php-2.14.0", function () {
$app->get("/braintree", function () {
   include 'views/response.php';
});
?>

this is braintree payments system i read the documentation clearly but not solved.error is found in this line 14: $app->get("/braintree", function () {

  • 写回答

1条回答 默认 最新

  • dtny30176 2012-09-14 14:55
    关注

    It looks like the problem is that anonymous functions are only available in PHP 5.3+. If at all possible I'd suggest upgrading your server to the newest version of PHP available, 5.4.7.

    Another issue might be that you're calling $app->run() before you add the response hook, so I'd move the run() call to the end.

    If you can't upgrade PHP then the following fix should work:

    <?php
    require_once 'braintree-php-2.14.0/lib/Braintree.php';
    require_once __DIR__ . 'silex/vendor/autoload.php';
    Braintree_Configuration::environment('sandbox');
    Braintree_Configuration::merchantId('...');
    Braintree_Configuration::publicKey('...');
    Braintree_Configuration::privateKey('...');
    $app = new Silex\Application();
    function form() {
      include 'views/form.php';
    }
    $app->get('/', form);
    function response() {
      include 'views/response.php';
    }
    $app->get("/braintree", response);
    $app->run();
    ?>
    

    The other reason I really like PHP 5.4 is that it includes a lightweight (ie not for production) server that makes testing and debugging a lot easier. I'm a Braintree dev and wrote the guide this came from so I hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗