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!

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

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像