bijan Posted October 31, 2012 Share Posted October 31, 2012 hi using a static counter variable in a class lets us to count the number of objects created so far is there a way to to access all Live objects instantiated from a class.(not just the number of them but the names of them !) i want to write a simple code for a human class . and in its __construct method i want that object to say hello to all previously created objects! Link to comment Share on other sites More sharing options...
Edward Posted October 31, 2012 Share Posted October 31, 2012 Yes you can do this by creating a static array, then you can assign each new instance of the newly created class to that array. This method is often used when storing active database connections. 3 Link to comment Share on other sites More sharing options...
Larry Posted October 31, 2012 Share Posted October 31, 2012 Good answer, Edward. Thanks! Link to comment Share on other sites More sharing options...
bijan Posted November 4, 2012 Author Share Posted November 4, 2012 Thanks Edward , but that static array should be a member of the class or declared out of the class? 1 Link to comment Share on other sites More sharing options...
Edward Posted November 5, 2012 Share Posted November 5, 2012 It should be a member of the base class. Then you can access the base class array to extract which value you need. Link to comment Share on other sites More sharing options...
Recommended Posts