我正在同时使用Wordpress和Laravel。
问题在于它们共享一个通用的函数名称(function __())。因此,我在Laravel中更改了名称:
[项目文件夹] \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ helpers.php
(938和947行)
它是__(),现在是___()。
并运行“作曲者更新”。
现在,Laravel和Wordpress运行时没有任何(可感知的)问题。但是每次我在Laravel中运行页面时,日志都会显示“调用未定义的函数__()”。
这是堆栈跟踪:
[2019-06-27 11:43:50] local.ERROR: Call to undefined function __() (View: C:\MyFolder\MyDevProjects\Laravel\projetofm\vendor\laravel\framework\src\Illuminate\Foundation\Exceptions\views\404.blade.php) {"exception":"[object] (ErrorException(code: 0): Call to undefined function __() (View: C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Exceptions\\views\\404.blade.php) at C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\storage\\framework\\views\\aef0b3ffdea5390a3697c2a0ec0b280e5440e2f8.php:2, Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to undefined function __() at C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\storage\\framework\\views\\aef0b3ffdea5390a3697c2a0ec0b280e5440e2f8.php:2)
[stacktrace]
#0 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Engines\\PhpEngine.php(47): Illuminate\\View\\Engines\\CompilerEngine->handleViewException(Object(Symfony\\Component\\Debug\\Exception\\FatalThrowableError), 1)
#1 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Engines\\CompilerEngine.php(59): Illuminate\\View\\Engines\\PhpEngine->evaluatePath('C:\\\\MyFolder\\\\MyD...', Array)
#2 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\View\\View.php(142): Illuminate\\View\\Engines\\CompilerEngine->get('C:\\\\MyFolder\\\\MyD...', Array)
#3 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\View\\View.php(125): Illuminate\\View\\View->getContents()
#4 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\View\\View.php(90): Illuminate\\View\\View->renderContents()
#5 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\Response.php(42): Illuminate\\View\\View->render()
#6 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\symfony\\http-foundation\\Response.php(202): Illuminate\\Http\\Response->setContent(Object(Illuminate\\View\\View))
#7 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ResponseFactory.php(55): Symfony\\Component\\HttpFoundation\\Response->__construct(Object(Illuminate\\View\\View), 404, Array)
#8 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ResponseFactory.php(81): Illuminate\\Routing\\ResponseFactory->make(Object(Illuminate\\View\\View), 404, Array)
#9 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Exceptions\\Handler.php(380): Illuminate\\Routing\\ResponseFactory->view('errors::404', Array, 404, Array)
#10 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Exceptions\\Handler.php(289): Illuminate\\Foundation\\Exceptions\\Handler->renderHttpException(Object(Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException))
#11 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Exceptions\\Handler.php(188): Illuminate\\Foundation\\Exceptions\\Handler->prepareResponse(Object(Illuminate\\Http\\Request), Object(Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException))
#12 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\app\\Exceptions\\Handler.php(49): Illuminate\\Foundation\\Exceptions\\Handler->render(Object(Illuminate\\Http\\Request), Object(Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException))
#13 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(83): App\\Exceptions\\Handler->render(Object(Illuminate\\Http\\Request), Object(Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException))
#14 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(32): Illuminate\\Routing\\Pipeline->handleException(Object(Illuminate\\Http\\Request), Object(Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException))
#15 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\fideloper\\proxy\\src\\TrustProxies.php(57): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#16 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#17 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#18 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#19 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#20 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#21 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#22 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#23 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#24 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#25 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#26 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#27 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php(62): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#28 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(163): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#29 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#30 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(104): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#31 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#32 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#33 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\public\\index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#34 C:\\MyFolder\\MyDevProjects\\Laravel\\projetofm\\server.php(21): require_once('C:\\\\MyFolder\\\\MyD...')
#35 {main}
"}
我认为“ composer update”会在整个项目中更新变量的名称。
如何在不产生此类冲突的情况下更改变量的名称?
谢谢。
答案 0 :(得分:0)
按照Jonnix的建议,我只是遵循错误日志并更改了所有函数调用。
最终只更改了这两个文件:
[项目 文件夹] \ storage \ framework \ views \ f1c5ee6d0afdfec4e103d6083eba089e6f755b96.php
[项目 文件夹] \ storage \ framework \ views \ aef0b3ffdea5390a3697c2a0ec0b280e5440e2f8.php
正如Jonnix指出的那样,这不是理想的解决方案。每当我更新Laravel时,都需要维护这些函数调用。
但是对于此问题的范围,由于它是一个临时的“ hack”,因此此解决方案将非常完美。
回顾一下,我应该使用Themosis之类的框架,按照MateiMihai的建议将Wordpress集成到Laravel中。
答案 1 :(得分:0)
我使用
{{ trans('my_file_in_my_lang_folder.my_phrase') }}
方法代替
{{ __(file.phrase) }}
__方法及其对我有用。
我的laravel版本
php artisan --version
Laravel Framework 5.2.20版
仔细检查:
/resources
/lang
/en
messages.php
/es
messages.php