php warning - 为foreach()提供的无效参数

时间:2014-02-02 16:27:24

标签: php mysql arrays yii

我安装了一个项目edusec学校管理系统,它在php mysql yii framework上工作。但是当我们复制它的根目录并在本地服务器上运行index.php时会出现以下错误?我做了什么?请帮帮我?

   PHP warning

Invalid argument supplied for foreach()

C:\xampp\htdocs\yiitest\protected\yii\framework\collections\CMap.php(288)

276      * @param array $b array to be merged from. You can specifiy additional
277      * arrays via third argument, fourth argument etc.
278      * @return array the merged array (the original arrays are not changed.)
279      * @see mergeWith
280      */
281     public static function mergeArray($a,$b)
282     {
283         $args=func_get_args();
284         $res=array_shift($args);
285         while(!empty($args))
286         {
287             $next=array_shift($args);
288             foreach($next as $k => $v)
289             {
290                 if(is_integer($k))
291                     isset($res[$k]) ? $res[]=$v : $res[$k]=$v;
292                 else if(is_array($v) && isset($res[$k]) && is_array($res[$k]))
293                     $res[$k]=self::mergeArray($res[$k],$v);
294                 else
295                     $res[$k]=$v;
296             }
297         }
298         return $res;
299     }
300 
Stack Trace
#0  
–  C:\xampp\htdocs\yiitest\protected\yii\framework\base\CModule.php(468): CMap::mergeArray(array("class" => "CDbConnection"), 1)
463         foreach($components as $id=>$component)
464         {
465             if($component instanceof IApplicationComponent)
466                 $this->setComponent($id,$component);
467             else if(isset($this->_componentConfig[$id]) && $merge)
468                 $this->_componentConfig[$id]=CMap::mergeArray($this->_componentConfig[$id],$component);
469             else
470                 $this->_componentConfig[$id]=$component;
471         }
472     }
473 
#1  
+  C:\xampp\htdocs\yiitest\protected\yii\framework\base\CComponent.php(153): CModule->setComponents(array("user" => array("allowAutoLogin" => true, "class" => "RWebUser"), "phpThumb" => array("class" => "ext.EPhpThumb.EPhpThumb"), "authManager" => array("class" => "RDbAuthManager"), "urlManager" => array("urlFormat" => "path", "rules" => array("<controller:\w+>/<id:\d+>" => "<controller>/view", "<controller:\w+>/<action:\w+>/<id:\d+>" => "<controller>/<action>", "<controller:\w+>/<action:\w+>" => "<controller>/<action>")), ...))
#2  
+  C:\xampp\htdocs\yiitest\protected\yii\framework\base\CModule.php(483): CComponent->__set("components", array("user" => array("allowAutoLogin" => true, "class" => "RWebUser"), "phpThumb" => array("class" => "ext.EPhpThumb.EPhpThumb"), "authManager" => array("class" => "RDbAuthManager"), "urlManager" => array("urlFormat" => "path", "rules" => array("<controller:\w+>/<id:\d+>" => "<controller>/view", "<controller:\w+>/<action:\w+>/<id:\d+>" => "<controller>/<action>", "<controller:\w+>/<action:\w+>" => "<controller>/<action>")), ...))
#3  
+  C:\xampp\htdocs\yiitest\protected\yii\framework\base\CApplication.php(144): CModule->configure(array("name" => "College Management System", "preload" => array("log"), "import" => array("application.models.*", "application.extensions.jtogglecolumn.*", "application.extensions.AjaxList.AjaxList", "application.components.*", ...), "modules" => array("gii" => array("class" => "system.gii.GiiModule", "password" => "secure", "generatorPaths" => array("ext.gii-extended"), "ipFilters" => array("127.0.0.1", "::1", "192.168.0.163")), 0 => "notification", 1 => "webservice", "rights" => array("install" => false, "superuserName" => "SuperAdmin", "authenticatedName" => "Authenticated", "userIdColumn" => "user_id", ...), ...), ...))
#4  
+  C:\xampp\htdocs\yiitest\protected\yii\framework\YiiBase.php(127): CApplication->__construct("C:\xampp\htdocs\yiitest/protected/config/main.php")
#5  
+  C:\xampp\htdocs\yiitest\protected\yii\framework\YiiBase.php(100): YiiBase::createApplication("CWebApplication", "C:\xampp\htdocs\yiitest/protected/config/main.php")
#6  
–  C:\xampp\htdocs\yiitest\index.php(18): YiiBase::createWebApplication("C:\xampp\htdocs\yiitest/protected/config/main.php")
13 
14 // specify how many levels of call stack should be shown in each log message
15 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
16 
17 require_once($yii);
18 Yii::createWebApplication($config)->run();
19 ?>
20 

2 个答案:

答案 0 :(得分:0)

第287行的array_shift()函数已返回null,因此$next不是数组。 当然foreach()需要一个数组。

答案 1 :(得分:0)

在传入循环之前验证该值。这将在数​​组为空时捕获。

  $next=array_shift($args);
  if ($next != null) 
  {
     foreach($next as $k => $v)
     {
        // do things here
     }
  }