![]() |
OOP Problem
ok ive been trying to figure this out for a while now...ive googled it and looked on oop tutorials and cant figure out whats wrong.
my index file is as follows: Code:
<?phpCode:
<?phpCode:
<?phpCode:
<?phpCode:
<p> |
Well that error implies that you are trying to call a function of an object that is not a valid object. For instance
$p->my_function(); instead of $p = new MyObject(); $p->my_function(); At a guess, I would say that the object is being instantiated in index.php (or a file included by index.php) and so therefore that file is working fine. However, in the other files (where you get an error), the error would suggest that you are not initialising an instance of the class, but rather, trying to access a function of a non existent class. I would ensure that the class is instantiated by looking back at index.php and it's included files, then ensuring you do the same on subsequent pages. |
I see the problem here. As you are including the files in your class itself, you're correct in that it inherits it, but it retains its scope. Therefore, take header.php as our example, because it is being included in the getHeader() function it will be included correctly, but be classed as part of the class.
Thus, in header.php you can still call the functions in your Layout class, but instead of using the object itself that you created when initiating your class, in your example, $System->Layout, it would simply by $this. Wrong: PHP Code:
PHP Code:
|
so if i just normally include the files in the index.php instead of the class should the class then work?
|
ahh yes it does work if i do that... thank you so much for your help wildhoney. i knew it would be something small and stupid but didnt know what it could be.
|
| All times are GMT. The time now is 07:22 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0