[英]Warning: Trying to access array offset on value of type null in C:
Hi I have been working all this week on this project that I'm helping my son with for his school project, the project is a PHP login script using the MVC design everything runs but I keep getting the following Warning: Trying to access array offset on value of type null in C:\wamp64\www\mvcloginregister\app\libraries\Core.php on line 18, line 18 is the following code:嗨,我这周一直在做这个项目,我正在帮助我儿子完成他的学校项目,该项目是一个 PHP 登录脚本,使用 MVC 设计一切正常,但我不断收到以下警告:尝试访问数组偏移量on value of type null in C:\wamp64\www\mvcloginregister\app\libraries\Core.php第18行,第18行代码如下:
// Look in BLL for first value
18 if(file_exists('../app/controllers/' . ucwords($url[0]). '.php')){
// If exists, set as controller
$this->currentController = ucwords($url[0]);
// Unset 0 Index
unset($url[0]);
}
I think the issue is in the following function
public function getUrl(){
if(isset($_GET['url'])){
$url = rtrim($_GET['url'], '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/', $url);
return $url;
}
}
I have reviewed all recommended answer related to this issue on this site and I'm unable to fix this issue I also found a post on google with the same issue but the person who fixed the issue did not post the solution which I think is rude and unprofessional.我已经在这个网站上查看了与此问题相关的所有推荐答案,但我无法解决此问题我还在 google 上发现了一个具有相同问题的帖子,但解决该问题的人没有发布我认为很粗鲁的解决方案和不专业。 Please help I'm very new to this php language and the MVC design.
请帮助我对这种 php 语言和 MVC 设计非常陌生。
Today I had the same problem and also couldn't find any solution around the web. Finally I've solved it by myself: added the $url variable to the condition inside the "if" statement.今天我遇到了同样的问题,也没有找到关于web的任何解决方案。最后我自己解决了:在“if”语句中的条件中添加$url变量。 this checks not only if the file exists but also if $url isn't null - like so:
这不仅会检查文件是否存在,还会检查 $url 是否不是 null - 就像这样:
$url = $this->getUrl();
if( $url && file_exists('../app/controllers/' . ucwords($url[0]). '.php') ){
$this->currentController = ucwords($url[0]);
unset($url[0]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.