I have two subclasses and I want to call a method in one subclass from another. Is the only solution to start chaining my classes in order of dependence? Sorry for the noob PHP question. Basically it's a common scenario to have multiple "base" classes such as an email class in which other subclasses will need access to. So do you just starting chaining them?
// In its own file (BaseClass.php)
require_once("./services/checkout.php");
require_once("./services/email.php");
class Base {
...
}
// In its own file (checkout.php)
class checkout extends Base {
public function onCheckout() {
// Call send email
$this->sendEmail($email); // <- How to do this?
}
}
// In its own file (email.php)
class email extends Base {
public function sendEmail($email) {
// Send email
}
}
source https://stackoverflow.com/questions/71442902/php-subclass-needs-another-subclass
No comments:
Post a Comment