Search code examples
phpyiicrashnotice

Yii 1.14 notice Undefined offset: 0 in CUrlManager.php


Hello i am facing this notice in my web application that powered on Yii 1.14 on a sub domain in godaddy and it crashes my application.

Undefined offset: 0

/home/uname/public_html/some_dir/yii/framework/web/CUrlManager.php(656)

 public function __construct($route,$pattern)
 {
     if(is_array($route))
     {
         foreach(array('urlSuffix', 'caseSensitive', 'defaultParams', 'matchValue', 'verb', 'parsingOnly') as $name)
         {
            if(isset($route[$name]))
                 $this->$name=$route[$name];
        }
         if(isset($route['pattern']))
             $pattern=$route['pattern'];
         $route=$route[0];
     }
     $this->route=trim($route,'/');

     $tr2['/']=$tr['/']='\\/';

     if(strpos($route,'<')!==false && preg_match_all('/<(\w+)>/',$route,$matches2))
     {
         foreach($matches2[1] as $name)
             $this->references[$name]="<$name>";
     }


$this->hasHostInfo=!strncasecmp($pattern,'http://',7) || !strncasecmp($pattern,'https://',8);

Solution

  • This error occurs if your config is corrupt. Check your config in:

    ['components']['urlManager']['rules']
    

    If you have set an empty array at this position, you'll get the reported error.

    return array(
        'components'    => array(
            'urlManager'   => array(
                    'rules' => array(
                        '<controller:\w+>/<id:\d+>'
                            => '<controller>/view', // fine
    
                        array(), // Won't work!!
                        '<controller:\w+>/<id:\d+>'
                            => array(), // Won't work!!
                    ),
            )
        )
    )
    

    Please check the documentation and update to the most recent version 1.1.15 which is an important security update.