PHP错误-意外的require_once预期功能 [英] Php Error - Unexpected require_once expecting function
问题描述
我目前正在尝试获取medoo框架,以便可以轻松地从MySQL数据库中检索数据...由于某种原因,它不起作用!
I'm currently trying to fetch the medoo framework so that I can begin easily retrieving data from my MySQL database... and for some reason it doesn't work!
这是我的 signin.php 文件的代码
<?php
function loginUserAccount($loginname, $password){
// Include Medoo (configured)
require_once 'medoo.min.php';
// Initialize
$database = new medoo();
$email = $database->get('MM_Users', 'Email', [
'ID' => 1
]);
return $email;
}
?>
错误:
分析错误:语法错误,意外的'require_once'(T_REQUIRE_ONCE),/myfiledirectory/example.php 中的期望函数(T_FUNCTION),位于 4
Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE), expecting function (T_FUNCTION) in /myfiledirectory/example.php on line 4
任何帮助将不胜感激!我不太确定发生了什么事情.
Any help is greatly appreciated! I'm not quite sure at what's going wrong.
正在运行的php文件是:
The php file that's running is :
<?php
require_once('signin.php');
if(!loginUserAccount('bobby@gmail.com', 'AveryRandomPassword')){
echo 'error';
} else {
echo $email;
}
?>
require_once的包装也有所不同……这没什么不同吗?如果是这样,更建议在生产环境中使用哪一个?
There's also a difference in the wrapping for require_once... this doesn't make a difference does it? And if so, which one is more advisable to use in a production environment?
推荐答案
没有函数的类中不能包含require_once
.
这是主要原因.
You can't have require_once
inside a class without a function.
That's the main reason.
尝试将require_once
放入construct
.
确切地说:
class foo
{
require_once('bar.php');
}
将引发错误.
这篇关于PHP错误-意外的require_once预期功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!