【问题标题】:SYMFONY 3.1 | TWIG - Markup.php (throwing error since migrating from 2.9.X)交响乐 3.1 | TWIG - Markup.php(从 2.9.X 迁移后抛出错误)
【发布时间】:2017-01-29 15:03:39
【问题描述】:

在将我的项目从 Symfony 2.9.X 升级到 Symfony 3.1.X 后,网站一直在抛出错误:

我目前对这个特定问题感到困惑,无法解决。

composer.json:

{
    "name": "jordan/.checkout",
    "license": "proprietary",
    "type": "project",
    "autoload": {
        "psr-4": {
            "": "src/"
        },
        "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "require": {
        "php": ">=5.5.9",
        "symfony/symfony": "3.1.*",
        "doctrine/orm": "^2.5",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/doctrine-cache-bundle": "^1.2",
        "symfony/swiftmailer-bundle": "^2.3",
        "symfony/monolog-bundle": "^2.8",
        "sensio/distribution-bundle": "^5.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "^2.0",
        "symfony/assetic-bundle": "^2.8.0"
    },
    "require-dev": {
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^3.0"
    },
    "scripts": {
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ]
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-bin-dir": "bin",
        "symfony-var-dir": "var",
        "symfony-web-dir": "httpdocs",
        "symfony-tests-dir": "tests",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        }
    }
}

【问题讨论】:

  • AppKernel.php - pastebin.com/aNUSYuYt 开发日志:pastebin.com/DwdGGkyY 产品日志:pastebin.com/iXqqudKZ
  • Markup.php 文件第 20 行及其附近的代码是什么?看来您只是缺少“使用”声明...其他错误似乎与您的 config.yml 有关,因此您也需要发布该声明。
  • 出现此错误时您使用的是哪个 PHP 版本?
  • PHP 7.0.15 这是我的服务器配置的最新版本,添加“使用”语句似乎无法解决问题。 config.yml 错误目前是警告,这些将在 Symfony 4 发布之前修补。但是,添加反斜杠 \JsonSerializable 解决了 Stephan 评论的问题。
  • 什么是人的问题?一个真正的问题,得到了答案,标记为已解决。现在大量的负面投票让我被禁止提问 - 这是你想要推广的那种社区吗?请考虑具有建设性!谢谢。

标签: exception twig migration symfony symfony-3.1


【解决方案1】:

JsonSerializable是PHP接口。

添加反斜杠以使用它:\JsonSerializable 而不是 JsonSerializable 或在文件顶部添加 use 语句 (use JsonSerializable;)。

否则,它会在你的bundle中查找(例如AppBundle\AppBundle\Twig\JsonSerializable,我不知道Markup.php在哪里)

【讨论】:

  • 谢谢,添加反斜杠已解决问题。 use 语句似乎不起作用,因为这是我的第一个想法。稍后,我将废弃项目文件并使用干净版本的 Symfony 3 并移植代码,因为太多的拼凑会导致以后出现问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-31
  • 1970-01-01
  • 2020-04-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多