Fatal error: Call to a member function on a non-object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jahangir
    New Member
    • Oct 2006
    • 22

    Fatal error: Call to a member function on a non-object

    Hello All,
    In my project I am using php calendar. I have used it locally it is working perfactly, but when I upload it on remote server it gives Fatal error: Call to a member function on a non-object in.......

    in second last line of following code where it gives problem;
    Code:
    function put_day($d, $font = 0, $color) {
    	
    		$cur_time = mktime(0, 0, 0, $this->a_selected_date['m'], $d, $this->a_selected_date['y']);
    		$d = date('j', $cur_time);
    		$m = date('m', $cur_time);
    		$y = date('Y', $cur_time);
    		$combine = $y."-".$m."-".$d; 
    		.....
                    ........
                    .......
    
    		$ar = $this->events_class->short_item($d, $m, $y);
    		$cset = $this->events_class->get_cell_settings($d, $m, $y);
    class structure is .

    Code:
    class calendar{
    	var $s_ImgDir; //an image folder absolute path
    	var $s_WebImgPath; //WEB path to the image folder (http://domain/calendar_files/img/)
    	var $s_FilesDir; //a main files folder absolute path
    	var $s_DataDir; //a data storage folder absolute path
    	var $db; //a variable for DB class
    	var $error; //a variable returns the error text message for previous calendar operation 
    	var $is_admin; //is true if calendar is called from control panel
    	var $is_created; //is true if current calendar name is just created
    	var $a_template; //an array that contain templates information
    	var $a_look; //an array that contains looks information
    	var $a_localization; //an array that contains information about localization
    	var $a_redirect; //an array that contains information about link redirect
    	var $a_current_date; //an array that contains current date of the following structure 
    	var $a_selected_date;//an array that contains selected date of the following structure 
    	var $s_calendar_index; //a string that contains current calendar name
    	var $events_class;
    }
    Kindly help in this regard,
    Thx
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Could you show us where you initialize the object 'events_class', which is causing the error?

    Comment

    • Jahangir
      New Member
      • Oct 2006
      • 22

      #3
      the initialization of events_class is in function init()

      [code=php]
      global $events;
      $events->events_file = $this->s_DataDir.'eve nt'.$this->s_calendar_ind ex.'.dat';
      $events->events_map_fil e = $this->s_DataDir.'eve nt_map'.$this->s_calendar_ind ex.'.dat';
      $this->events_class = $events;
      ....
      ....
      ...
      $this->events_class->load_item();
      [/code]

      I find "load_item( )" in events.php

      Thx
      Last edited by Atli; Aug 18 '07, 01:49 PM. Reason: Changed [code] tags to php

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        The global variable '$events' there is used like an object, but It is never initialized as an instance of any class.

        According to this code, the second line should cause the same error you mentioned earlier, unless the '$events' variable is initialized somewhere else?
        Edit: After a little testing, I found that line 2 should work fine, but at line 8, you should see an error.

        Also, why do you make it global? If you are just going to pass it right on to the 'events_class' variable?

        Comment

        • Jahangir
          New Member
          • Oct 2006
          • 22

          #5
          Dear actually, I am doing maintaince of this project,

          I was previously working fine even at localhost, but as some other files I upload, this type of error , i met.

          I shall be gr8 ful for cooperation.

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Originally posted by Jahangir
            Dear actually, I am doing maintaince of this project,

            I was previously working fine even at localhost, but as some other files I upload, this type of error , i met.

            I shall be gr8 ful for cooperation.
            If this has worked before, the 'events_class' object must be initialized somewhere, as a instance of some class.
            The last code you posted indicates that the 'events_class' object has not been initialized before you use it, which would cause PHP to automatically initialize it as 'stdClass' which contains no definition for a 'load_item' function. That should cause the error you mentioned.

            What type of class should it be? Where is it initialized as an instance of that class?

            Did you perhaps forget to move a file to the server? Does the server have a different, out of data, version of PHP?

            Comment

            • Jahangir
              New Member
              • Oct 2006
              • 22

              #7
              I have reload all the project files more than 2 times. The event_class is defined in events.php in same folder as calendar.php.

              On local host all thing is working fine..but I dont get what problem is in online site?

              Comment

              Working...