I have 3 classes with the following inheritance structure:
<?php
class admin {
function __construct($module){
echo $module;
}
}
class user_admin extends admin {
function __construct(){
parent::__construct('user');
}
}
class sales_admin extends user_admin {
function __construct(){
parent::__construct('sales');
}
}
You'll notice that the sales_admin extends the user_admin, this is a nescessary step. When I run this code,
$a = new sales_admin;
it will echo "user", because it passes the "sales" string to the user_admin which doesn't accept a constructor.
Is there a way to access the constructor of the parent above it without changing the user_admin, which I don't have control over?
Just reference the class directly:
class sales_admin extends user_admin
{
function __construct()
{
admin::__construct('sales');
}
}
$a = new sales_admin; // outputs 'sales'
Since user_admin extends admin, and sales_admin extends user_admin, sales_admin will have scope of the admin constructor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With