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 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办