473,545 Members | 527 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hi,

I'm having a problem that I have a hard time understanding. I am getting a
"Fatal error: Call to a member function on a non-object" on a constructor
of a class, that looks like this (simplified):

class phpBB_Template {
var $classname = "Template";

// Root template directory.
var $root = "";

/**
* Constructor. Simply sets the root dir.
*
*/
function phpBB_Template( $root = ".")
{ /* Error is reported on this line */
$this->root = $root;
}
}

The line where the error is reported only contains the function's opening
accolade. As far as I understand, this error should only occur if I try to
access a function on a variable that is not an object, but the only
variable I am accessing, is $this, and that one is by definition an object,
right?

Please help!

André
Jul 17 '05 #1
2 28007
André Somers wrote:
I'm having a problem that I have a hard time understanding. I am getting a
"Fatal error: Call to a member function on a non-object" on a constructor
of a class, that looks like this (simplified):

Please ignore the above, I just wasn't looking hard enough. The problem was
in a different file with a very similar name... Silly me...

André

Jul 17 '05 #2
Hi,

your code works fine on my computer. have you tried this:

class phpBB_Template {
var $classname = "Template";

// Root template directory.
var $root; //<----change here!

/**
* Constructor. Simply sets the root dir.
*
*/
function phpBB_Template( $root = ".")
{ /* Error is reported on this line */
$this->root = $root;
}
}

i think in php4 you're not supposed to declare non-constand vars like
that: var $root = "blah".


André Somers wrote:
Hi,

I'm having a problem that I have a hard time understanding. I am getting a
"Fatal error: Call to a member function on a non-object" on a constructor
of a class, that looks like this (simplified):

class phpBB_Template {
var $classname = "Template";

// Root template directory.
var $root = "";

/**
* Constructor. Simply sets the root dir.
*
*/
function phpBB_Template( $root = ".")
{ /* Error is reported on this line */
$this->root = $root;
}
}

The line where the error is reported only contains the function's opening
accolade. As far as I understand, this error should only occur if I try to
access a function on a variable that is not an object, but the only
variable I am accessing, is $this, and that one is by definition an object,
right?

Please help!

André


Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
16504
by: Daniel Hansen | last post by:
I am getting a "Fatal error: Call to undefined function: imagecreatefromjpeg() in..." error in one of my scripts, and after doing a bit of searching on the 'net I found various messages relating to a failure to have the GD library installed. However, my phpinfo() reports (in the Apache GD section): GD Support enabled GD Version bundled...
3
2432
by: PeterF | last post by:
Hello, what is wrong here? the purpose is to create an array of objects and then interate over it, calling some method from all of them. I get just the following at the marked line ("// FATAL ERROR"): Fatal error: Call to a member function on a non-object See the code:
4
15335
by: gc | last post by:
I'm a PHP and MySQL newbie. I have a feeling a lot of you may have seen this before. I'm teaching myself PHP/MySQL and trying to setup a guestbook. I'm running latest versions of Apache, PHP and MySql on WIN 2000. PHP is installed from the zip file. When serving php docs (code snippets below) I get the messages: "Fatal error: Call to...
8
9984
by: Tim Tyler | last post by:
I'm getting fatal errors when executing code - and my error handler is failing to trap them - so I get no stack backtrace :-( The error I am getting is: "Fatal error: Call to a member function fetchRow() on a non-object." What are the available options here? Am I supposed to check I have a real object whenever I perform
2
2393
by: dmitry.freitor | last post by:
Why would someone call a non-static provate member function from another non-static member function of the same class via the this pointer? Thanks. DF
7
32083
by: Ook | last post by:
What am I doing wrong? This code gives a compile error: 'SortedList<T>::insert' : illegal call of non-static member function. I've tried several variations of this, but keep getting the same error. template <typename T> class SortedList { public: void insert( T item); // Write this
4
3845
by: Jesper Stocholm | last post by:
I have a recursive function that I would like to do a lot of recursive calls (preferebly 2^20 in total) The function is called as (with maxi = e.g. 100000) DoRecursion(0,maxi,bseed,sha); And the total code is static void Main(string args)
6
4396
by: Bill Rubin | last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the same invocation from a DistantlyRelated class. What actually happened was that the compiler produced: error C2247: 'A::function' not accessible...
12
2508
by: mast2as | last post by:
Hi everyone... I have a TExceptionHandler class that is uses in the code to thow exceptions. Whenever an exception is thrown the TExceptionHander constructor takes an error code (int) as an argument. I was hoping to create a map<int, const char*that would be used in the showError member function of the TExceptionHandler class where the key...
2
6096
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my pointers, but I'm not sure. Please help. The code: void equate(matrix *A, matrix *B) { int i, j; assert(A.row_dim == B.col_dim && A.col_dim ==...
0
7396
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7413
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7751
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5323
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.