zerke2001 Posted July 9, 2010 Share Posted July 9, 2010 Hi everyone! I am working on a project that I am ramping up my involvement with OOP. So far I have made classes and instantiate objects, this is not new to me btw. During my search for info on another project I came across a Visual Basic article on "Shared Members and Instance Members". I realized the way VB uses what they call "Shared Members" is exactly what I am looking for. I have designed my code to use classes, but when you instantiate them, the create separate objects that can't share info between them like "Shared Members" do in VB. I have created an awesome class for connecting to MySQL. However, I believe there is something fundamentally wrong with the way I have designed it. When you instantiate the MySQL class I made, you pass variables such as the username, pass, host, and table to it. The real problem with this is that each object is for one table. Since I have a table for properties, and a table for pictures, I can't just call the properties class to delete pictures from the pictures class because they are in 2 different MySQL objects that can't access the info between them. I haven't seen a solution to do either of these things. The "Shared Members" concept seems like a great idea, but I don't think PHP does this. If you need me to clarify anything let me know. Any help would be Greatly Appreciated!!! Link to comment https://forums.phpfreaks.com/topic/207225-is-it-possible-to-have-a-shared-member-class/ Share on other sites More sharing options...
Mchl Posted July 9, 2010 Share Posted July 9, 2010 I believe what you refer to as 'shared members' are called 'static class variables' in PHP. I'm not sure however, if using these is the best way to do what you want to do. A common way to do it is to have a MySQL connection class (often using mysqli) which is passed to different data access classes so that they can use it. Link to comment https://forums.phpfreaks.com/topic/207225-is-it-possible-to-have-a-shared-member-class/#findComment-1083460 Share on other sites More sharing options...
zerke2001 Posted July 9, 2010 Author Share Posted July 9, 2010 Thanks! I think this should work. I will start working on it soon and let you know if I need anything else. Link to comment https://forums.phpfreaks.com/topic/207225-is-it-possible-to-have-a-shared-member-class/#findComment-1083725 Share on other sites More sharing options...
zerke2001 Posted July 15, 2010 Author Share Posted July 15, 2010 Hello Mchl and everyone else! I wanted to return my feedback on the results of Mchl's suggestion. Static Class Variables and functions was exactly what I was looking for! However, my solution was to use a mixture of the Static Classes and the Object Classes. For the MySQL Connection super class I created, I used the Object Class, and the rest (i.e. Properties, Pictures and Users), I used the Static Classes and instantiated the MySQL super class within them. The reason I did this and why it worked was that I needed a way to query the properties, pictures and users that are all in separate tables to display them. I wanted to update the data, but also to call simple methods like "deleteProperty()" which would not only delete the row from the DB, but also delete the pictures, and the pictures row in the DB. So there is this tight integration I just couldn't get my head around. OOP requires you to really think about the design and structure you are creating. Careful planing is the key, otherwise you might have to scrap hours of work because of a design flaw. Thanks again Mchl!!!! Link to comment https://forums.phpfreaks.com/topic/207225-is-it-possible-to-have-a-shared-member-class/#findComment-1086305 Share on other sites More sharing options...
Mchl Posted July 15, 2010 Share Posted July 15, 2010 Nice to hear that you're managed that well Link to comment https://forums.phpfreaks.com/topic/207225-is-it-possible-to-have-a-shared-member-class/#findComment-1086309 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.