Forum Moderators: coopster

Message Too Old, No Replies

List all objects of a certain class

Array of instantiated objects

         

TomAnthony

1:59 am on Apr 3, 2006 (gmt 0)

10+ Year Member



Is it possible to get a list of all current objects for a given class in PHP5?

Many thanks.

scriptmasterdel

9:34 am on Apr 3, 2006 (gmt 0)

10+ Year Member



Have you tried printing out an array of objects from your class?

<?
$class = new class();
// format the output using <pre>
echo '<pre>';
print_r($class);
echo '<pre>';
?>

.. this should work!

Del

TomAnthony

11:59 am on Apr 3, 2006 (gmt 0)

10+ Year Member



Thanks for the reply. I didn't phrase my question properly.

What I want to do is this:


$foo = new moof("one");
$baa = new moof("two");
list_objects_of_type(moof); // outputs references to $foo and $baa in array

I need some way of doing what my made up function (list_objects_of_type) does.

My current solution is to use a static class variable array that appends a reference to $this in the constructor, and scrubs it in the destructor.

My solution works great, but I thought maybe there was a 'proper' way to it.