php - Uninitialized first variable on a function -


i have strange problem php , codeigniter. here's code of file:

edit: skip code , go second 1 wrote. remains here in case might useful.

<?php if ( ! defined('basepath')) exit('no direct script access allowed');  require_once ( 'utils.php');  class footerheader {    // esta clase nos permite definir el footer y sus correspondientes menus   var $utils;   var $controller;    var $topmenu_not_logged_in_names;   var $topmenu_not_logged_in_links;   var $topmenu_logged_in_names;   var $topmenu_logged_in_links;   var $topmenu_designer_names;   var $topmenu_designer_links;    // side menu   var $sidemenu_not_logged_in_names;   var $sidemenu_not_logged_in_links;   var $sidemenu_logged_in_names;   var $sidemenu_logged_in_links;   var $sidemenu_designer_names;   var $sidemenu_designer_links;    // main menu   var $mainmenu_not_logged_in_names;   var $mainmenu_not_logged_in_links;   var $mainmenu_logged_in_names;   var $mainmenu_logged_in_links;   var $mainmenu_designer_names;   var $mainmenu_designer_links;    function footerheader ($controller) {     $this->utils = new utils ();     $this->controller = $controller;     include_once 'definemenus.php';     configvars ($this);   }    public function setdefaultheader ($situation) {     $topmenunames = array();     $topmenulinks = array();     $mainmenunames = array ();     $mainmenulinks = array ();     $sidemenulinks = array ();     $sidemenunames = array ();      // dependiendo del estado del usuario, mostramos cosas u otras     if ($situation == not_logged_in) {       $topmenunames = $this->topmenu_not_logged_in_names;       $topmenulinks = array ('users/login', 'users/register');       $mainmenunames = $this->mainmenu_not_logged_in_names;       $mainmenulinks = $this->mainmenu_not_logged_in_links;       $sidemenulinks = $this->sidemenu_not_logged_in_names;       $sidemenunames = $this->sidemenu_not_logged_in_links;     }     else if ($situation == loged_in) {       $topmenunames = $this->topmenu_logged_in_names;       $topmenulinks = $this->topmenu_logged_in_links;       $mainmenunames = $this->mainmenu_logged_in_names;       $mainmenulinks = $this->mainmenu_logged_in_links;       $sidemenulinks = $this->sidemenu_logged_in_names;       $sidemenunames = $this->sidemenu_logged_in_links;     }     else if ($situation == designer) {       $topmenunames = $this->topmenu_designer_names;       $topmenulinks = $this->topmenu_designer_links;       $mainmenunames = $this->mainmenu_designer_names;       $mainmenulinks = $this->mainmenu_designer_links;       $sidemenulinks = $this->sidemenu_designer_names;       $sidemenunames = $this->sidemenu_designer_links;     }     var_dump ($topmenulinks);     $this->setheader ($topmenulinks, $topmenunames, $mainmenulinks, $mainmenunames, $sidemenulinks, $sidemenunames);   }    public function setheader ($topmenulinks, $linknames, $menus, $menusnames, $sidemenulinks, $sidemenunames) {     var_dump ($topmenulinks);     $enlaces = $this->generatetopmenu ($linknames, $topmenulinks);     $data['enlaces'] = $enlaces;     $menus = $this->generatemenus ($menusnames, $menus);     $data['menus'] = $menus;     $sidemenus = $this->generatesidemenu ($sidemenulinks, $sidemenunames);     $data['sidemenus'] = $sidemenus;      $this->controller->load->helper('html');     $this->controller->load->view('static/header.php', $data);   } [...] } 

do not read all. it's not necessary. @ 2 var_dump calls. first var_dump prints out:

array (size=2)   0 => string 'users/login' (length=11)   1 => string 'users/register' (length=14) 

the second one:

array (size=0)   empty 

i don't know why variable uninitialized. rest of variables ok.

edit: have simplified code max:

<?php class footerheader {    function footerheader ($controller) {     $this->controller = $controller;   }    public function setdefaultheader ($situation) {     $topmenulinks = array();     // dependiendo del estado del usuario, mostramos cosas u otras     $topmenulinks = array ('users/login', 'users/register');     var_dump ($topmenulinks);     $this->setheader ($topmenulinks);   }    public function setheader ($topmenulinks) {     var_dump ($topmenulinks);   } }  ?> 

but problem still occuring.

edit: code doing calling this:

<?php if ( ! defined('basepath')) exit('no direct script access allowed');  require_once ( 'utils/footerheader.php'); require_once ( 'utils/definemenus.php');  class welcomepage extends ci_controller {    var $fh;    function welcomepage () {     parent::__construct();     $this->fh = new footerheader($this);      $this->load->helper('url');   }     public function index()     {     // seteamos el header (el defecto)     $this->fh->setdefaultheader(not_logged_in);      $this->load->view('subirdisenyoejemplo.php');      //$this->fh->setfooter();     } }  /* end of file welcomepage.php */ /* location: ./application/controllers/welcomepage.php */ ?> 

edit: watch out capitalization:

var_dump ($topmenulinks); $this->setheader ($topmenulinks); 

$topmenu l inks vs. $topmenu l inks. tried on server, , popped uninitialized variable.

originally:

the content of array depends on outcome of if - else if construct. in case

if ($situation == not_logged_in) { 

will array assigned value in first var_dump(). otherwise, end empty array because initialized

$topmenulinks = array(); 

if have situation not covered loged_in or designer. watch out missing g in loged_in.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -