stuart475898 Posted May 29, 2009 Share Posted May 29, 2009 I have a program (procedural) that when started, instantiates a couple of different classes (class A and class B). My question is, is it possible to access class A from class B, or do I have to instantiate class A again in class B? Thanks for any help Sorry this topic is in the wrong area, I thought I had navigated back from the regex forum when I started the topic Quote Link to comment https://forums.phpfreaks.com/topic/160159-class-scope/ Share on other sites More sharing options...
Maq Posted May 29, 2009 Share Posted May 29, 2009 Yes it is possible. There are multiple techniques depending on what exactly you're trying to do. Please provide a little more detail. This has nothing to do with regular expressions, moving to php help. Quote Link to comment https://forums.phpfreaks.com/topic/160159-class-scope/#findComment-845001 Share on other sites More sharing options...
Ken2k7 Posted May 29, 2009 Share Posted May 29, 2009 Well you can access public static fields and methods in class A from anywhere with no problems. If B extends A, then of course (minus private fields and methods). Quote Link to comment https://forums.phpfreaks.com/topic/160159-class-scope/#findComment-845004 Share on other sites More sharing options...
stuart475898 Posted May 29, 2009 Author Share Posted May 29, 2009 Thank you for your reply. I am working on a program that uses the betfair api. I have a main class which handles all of the requests sent to betfair and does some basic error handling, and this class is started from the main program. I also have a number of other classes which perform functions on market information, but sometimes these other classes need to send a request to betfair (via the main class). MAIN PROGRAM / \ / \ / \ Main Class Market Processing Class The main program starts all classes, and then sends a request to betfair for market details via the main class. This data is then passed to the market processing class. However, the market processing class might need to send a request to betfair, and needs to use the main class. Quote Link to comment https://forums.phpfreaks.com/topic/160159-class-scope/#findComment-845010 Share on other sites More sharing options...
Daniel0 Posted May 29, 2009 Share Posted May 29, 2009 That "main class" doesn't sound too good. http://en.wikipedia.org/wiki/God_object Quote Link to comment https://forums.phpfreaks.com/topic/160159-class-scope/#findComment-845018 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.