![]() |
Classes (Explained inside)
Hi There as you can tell i am new to the community so firstly.
Hey all :D Right to go into my problem. This is to write my own class base and core system. Read the code below to understand me further. So all classes below will be seperate files. and will be included seperatly. PHP Code:
Fatal error: Call to a member function error() on a non-object Hope i explained it ok :(. Basicly i need to be able to use the classes i setup in the Base obj. Thank you so so much in advanced :D |
1) I don't think you need to include Database, it should be 'auto-added' into the Base class.
2) Why not use separate variables for each class? (e.g. $database, $system, $validation...) |
In a hurry notice, I would say that it is because the error method has to have an argument to work. But the 'on a non-object' part tells me that the $Base->Database property is not an object instantiation.
Maybe changing this: PHP Code:
PHP Code:
I don't remember very well the syntax rules in using variables as processing code text. |
You'll probably need to a) load the logging class as an object of your database class, or b) declare the necessary properties as static and reference it via 'parent::' from your child class.
Your Database object, even though it extends the Base class, does not have access to the same properties that your Base object does. This is because they are essentially two seperate objects with their own set of properties - they're just sharing methods (physically they wouldn't share the same bubble, each is inside their own). You can visualize this by declaring some random properties in each, and then dumping $this with print_r() or var_dump(). This would probably be a great time to learn about design patterns. In particular, you might want to learn how to generate a singleton. Rather straight forward, and I believe Tony Marston has a very good write up on how to go about it on his site. -m |
Database is not a variable nor function inside Base class so you cannot access it via $base->Database.
You would need a __get method and retrieve the object from an array of objects. And you also need to store the objects in that array when you use load_class. |
Tanax is correct, just because an class 'extends' another it doesn't mean that the 'base' class will have any knowledge of any derived objects. To add this functionality you would need to store the object in an array in the base object and use a getter to access it (as Tanax suggested you could use the magic get interceptor function __get)
|
Thank you all so much for your replys, When i get a some spare time will put into place some the ideas you have provided. Wasn't expecting such a great response :D.
Liking this community already. |
| All times are GMT. The time now is 10:37 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0