I have a big PHP project in which I didn't use any framework (nor MVC pattern), and I want to gradually port it on Laravel with (almost) no downtime.
I'm searching for ways of making transparent the migration for pieces of code already ported to Laravel, while mantaining functional older plain PHP code.

For example, Laravel "overwrites" superglobals ($_GET, $_POST, etc.) using classes and methods, (ex. Input::get()). My plain PHP project of course makes direct use of superglobals. How can I overcome these "uncompatibilities" under Laravel without having to rewrite instantly all my PHP code?

Otherwise, if you think this task being too difficult, is there any PHP framework that, thanks to its internal structure, would make this task easier?

UPDATE:
The use of superglobals is still possible in laravel. I was getting a sneaky error: Laravel internally sets error_reporting to E_ALL and shows a custom error stack trace page even for PHP E_NOTICE, but without explicitly specifying the error level (that it is a NOTICE error), even if this was done by default by PHP error reporting message engine.

Let me say, for Laravel core developers, that I consider this "partially silent" behaviour as generally misleading for any PHP developer trying to port his code on to their framework.

推荐答案

TL;DR

不要这样做.

Common misconception

If you have an existing project, then grafting it on a framework will gain you no benefits. Frameworks are not some magic sauce, which miraculously makes the code better or make the site run faster.

Instead, frameworks are tools, that (supposedly) help you write the project in a shorter amount of time by having the "common tasks" already done. Also, as a side effect, it is extremely difficult to stop using a framework in a project (if it, for example, gets discontinued), because all of your code now is tightly welded to a framework.

这就是您当前遇到这些问题的原因:

  • 我如何克服Laravel下的这些"不兼容性",而不必立即重写所有PHP代码?

    You cannot. Rewrite it exactly as the Laravel framework wants you to or it won't work.

  • (..) is there any PHP framework that, thanks to its internal structure, would make this task easier?

    不,没有.所有流行的框架都希望您重写代码,以便将其绑定到框架.

The better approach

But you already have a working application. You will have better results, if you focus on improving the existing code base:

  • make sure you follow SOLID principles
  • separate your business logic from you presentation and database abstraction
  • 开始为代码的really shady个部分添加单元测试
  • refactor, refactor, refactor

P.S.: the materials listed here wold probably help

Laravel相关问答推荐

Uncaught ReferenceError:未定义require[Shopify PHP React Browser问题]

如何在 laravel 中为另一个用户 session()->forget('cart')?

在 Laravel 中设置多个 Vue 组件的问题

Laravel - 出于某种原因,max 打破了我的查询

在 apache docker 容器中运行虚拟主机

如何为路由 laravel 5 使用OR中间件

Laravel:Blade foreach 循环 bootstrap 列

Laravel 4,如何测试复选框是否被选中?

PHP 中的 Http 响应代码枚举

升级到 laravel 5.4 后调用未定义的方法

带有消息...必须返回关系实例的 LogicException.

file_put_content ...无法打开流:Laravel 5 中的权限被拒绝

artisan 迁移错误找不到类'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver'

未找到 PHP 5.4 和 Laravel 类Memcached

如何在 Laravel 5.2 中手动发送密码重置请求?

如何使用中间件将标头添加到响应中?

Laravel 5.1-5.8 中以前的路由名称

如何在 php Laravel 中对关联数组进行排序

是否可以将路由参数传递给 Laravel 中的控制器构造函数?

将参数传递给过滤器 - Laravel 4