473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 27998
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
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...
3
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...
4
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...
8
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...
2
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
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....
4
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); ...
6
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...
12
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...
2
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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,...

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.