简体   繁体   English

Laravel本地虚拟主机在MAMP服务器上返回FatalErrorException

[英]Laravel local virtual host returning FatalErrorException on MAMP server

I am working on a project, I decided to create local virtual host to keep my URL clean and easy. 我正在做一个项目,我决定创建本地虚拟主机,以保持URL整洁。

When ever I hit a route that uses a controller it returns this error: Symfony \\ Component \\ Debug \\ Exception \\ FatalErrorException Can't use function return value in write context 每当我碰到使用控制器的路由时,它将返回以下错误:Symfony \\ Component \\ Debug \\ Exception \\ FatalErrorException无法在写入上下文中使用函数返回值

I cannot figure what is causing this. 我不知道是什么原因造成的。

Anyone else run into this type of error on this environment? 在此环境中,还有其他人遇到此类错误吗? Any tips are appreciated. 任何提示表示赞赏。 Thank you. 谢谢。

There are two general causes for this error. 导致此错误的一般原因有两个。 The first is something like this: 首先是这样的:

echo $_POST('test');

Notice that instead of indexing the array, you're calling a function. 注意,您不是在索引数组,而是在调用函数。 This will cause this error. 这将导致此错误。 Another cause of that particular error could be something like this: 导致该特定错误的另一个原因可能是这样的:

$test = ' ';
if(empty(trim($test)) { // There be dragons

This is because the only valid arguments to the empty function are variables (you cannot call a function inside the call to empty ). 这是因为empty函数唯一有效的参数是变量(不能在对empty的调用内调用函数)。 Per the docs : 根据文档

Note: Prior to PHP 5.5, empty() only supports variables; 注意:在PHP 5.5之前,empty()仅支持变量。 anything else will result in a parse error. 其他任何情况都会导致解析错误。 In other words, the following will not work: empty(trim($name)). 换句话说,以下内容将不起作用:empty(trim($ name))。 Instead, use trim($name) == false. 而是使用trim($ name)== false。

The same restrictions on empty also apply to isset as well . 在同样的限制empty也适用于isset

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM