PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm just wondering, in the interests of decreasing maintenance of my data object classes would the following work to include extra methods into the class?
<?php
class SomeClass{
var $classname = 'SomeClass';
// Some properties
function SomeClass(){
//Some code
}
// Some more methods
include($this->classname . '_extras.inc.php');
}
?>
If not, is there a way I can accomplish this that would remain php4 compatible?
No, you can't have logic or includes outside of class methods, all you can do directly in your class{} block is declare properties really. What's wrong with extensions or plugins? You might want to look into sticking these methods you're referring to into smaller classes and then using a registry of some sort to contain what you need, when you need it
The DataObject class is the parent class for an unknown number of child classes.
Each child class will have a specific set of methods that are specific to that child but are directly related to the database table the class is built to interface with.
These child classes can be generated by another script whenever the database schema changes by extracting the database details.
Some child classes may have additional methods that are there for convenience. These convenience methods could not be automatically extrapolated from the database.
The child classes are the ones that have to be instantiated for use in the rest of the application.
This is why I was wondering if it was possible to include additional methods dynamically.