• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
another situation which cause Fatal error: Call to a member function on a non-object

#11
[eluser]sparkling tux[/eluser]
Hey, man!

I've just tried to add

Code:
parent::Controller();

not in the constructor of my controller but in the controller's method, i.e.

Code:
function show_all_records()
{
    parent::Controller();
    
    $this->load->model('Blogmodel', '', TRUE);
    
    $d['query'] = $this->Blogmodel->get_last_ten_entries();
    $this->load->view('qview', $d);
}

And, *MAGIC*, it started working!

#12
[eluser]barbazul[/eluser]
I already mentioned this behavior in http://www.ellislab.com/forums/viewthread/52308/

One of the posible solutions was moving all the $this->load->something() lines to the constructor.
The other, which worked perfectly for me, was changing the hosting company

#13
[eluser]tonanbarbarian[/eluser]
Ok I have just run across a similar problem to this and found a solution so I thought I would share with everyone.

Was continually getting the following error on PHP 4 but not PHP 5

Fatal error: Call to a member function on a non-object in F:\Websites\test.local\musicadium\controllers\admin\upcs.php on line 100
PHP Fatal error: Call to a member function on a non-object in F:\Websites\test.local\musicadium\controllers\admin\upcs.php on line 100

I setup a test server on IIS so that I could easily try different PHP versions and found that if using any version of PHP 5 it worked but all the versions of PHP 4 tested failed.

This lead me to think that it was either a referencing issues as others have thought, or some code that was actually PHP 5 specific was causing the problem

The first thing that caught my attention was that the line number being reported in the error should never have been called. This was trying to call the index() method of the controller yet the error was being reported in the next method called view()

So I stepped through the code and tried to find where the problem was. I tried to change the code to not use references and I finally traced the code to a call to
Code:
$this->load->view()

Spent an hour trying several things to work out exactly what was causing the problem when I finally started to look more at the fact that the error was in the controller::view() method.

Then it hit me....

I renamed the view() method to view2() and suddenly my error disappeared and everything (except for the links to the view() method) was working correctly.

All I can think that is happening is that PHP is getting confused with the referencing and rather than trying to call $this->load->view() somehow it is calling $this->view() which calls the view in the controller and that is causing the issue.

What I have got out of this is to be careful when creating controller methods that are the same name as other methods used by libraries such as Loader.

I have no idea if this will fix the problems listed here but my issue seemed at first glance to be the same as mentioned here.

#14
[eluser]sparkling tux[/eluser]
Thanks for the reply!
I don't think my issue is equal to yours. My code works fine in almost any platforms I've tested it but (what an unfortunate!) crashes on the hoster's server. Moreover, my hoster have machines with PHP4 and PHP5, and on the former everything is OK.

#15
[eluser]StevenW721[/eluser]
[quote author="barbazul" date="1189704403"]I already mentioned this behavior in http://www.ellislab.com/forums/viewthread/52308/

One of the posible solutions was moving all the $this->load->something() lines to the constructor.
The other, which worked perfectly for me, was changing the hosting company[/quote]
I had the same issue and it turned out to be the host in my case as well. Unfortunately changing hosts is impossible for me so I researched the problem more and found out a solution. I posted it in your other thread barbazul here. Hope this helps someone else!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.