douzheng0702 2012-09-13 20: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 06: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!

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部