Saving Classes

I have a class Class1 saved in Class1.php in the /classes directory.

If I create Class2 extends Class1, should I create Class2 in the Class1.php file or create it in Class2.php?

If I create it in Class2.php, how do I reference Class1 when I instantiate a new object of Class2?

Either way works, but 99% of the time I prefer to put each class in it’s own file. The only time I break that rule is when I have a second class that is needed by (and only by) the first class.

As for calling it, you just need to include both Class1.php and Class2.php, then initiate the object, i.e.
$class2 = new Class2;

It might be a good time to get autoload going (if you’re not already using it) as you’ll find the more classes you write the including will grow to the point of ridiculousness.

Thanks again. Makes sense and yes I agree on autoload. I have an Advanced PHP5 book that goes into that so off I go. :slight_smile:

That’s much easier. Works great. Thanks again. :slight_smile: