我收到PHP通知错误。这段代码在php 5.3中运行良好,但是后来我将PHP升级到了PHP7。我想要做的是从链接中获取URL,然后仅显示URL附带的参数。这是代码。
index.php
<?php
require_once('bootstrap.php');
$bootstrap = new Bootstrap($_GET);
?>
bootstrap.php
<?php
class Bootstrap{
private $controller;
private $action;
private $request;
public function __construct($request){
$this->request = $request;
if($this->request['controller'] == ''){
$this->controller = "Home";
}
elseif($_GET($request['controller'])){
$this->controller = $this->request['controller'];
}
if($this->request['action'] == ''){
$this->action = "index";
} else{
$this->action = $this->request['action'];
}
echo "<br />$this->controller<br />$this->action";
}
?>
转到URL的输出:localhost / myDir / index.php / abc / def
注意:未定义的索引:在第8行的/srv/http/myDir/bootstrap.php中的控制器
注意:未定义的索引:在第14行的/srv/http/myDir/bootstrap.php中的操作
房屋
指数
测试empty()
...将为true
0,'0',false,'',空array()...,通知也消失了!...对您的其他if和数组索引执行相同的操作!
if(empty($this->request['action'])) {
为了避免类似的警告,您还应该在方法,函数等中提供默认值:
function ($arg=FALSE, $arg2=TRUE, $arg3=5, ...) {
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句