Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8347673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:26:16+00:00 2026-06-09T07:26:16+00:00

abstract class User { protected $content; // $content object will be assigned here }

  • 0
abstract class User
{
  protected $content; // $content object will be assigned here


}

class Member extends User
{

}


abstract class Content
{
 function create()
 {
  //create some content
 }
}

class Text extends Content
{

}

class Image extends Content
{
}

Abstract User can extend to other classes based on rolls which are customizable. Each roll has a different permission to use Content class, and it’s child classes method. I can write manually each permission for each method, but I want to do that dynamically.

How can I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:26:17+00:00Added an answer on June 9, 2026 at 7:26 am

    UPDATE

    On reading your question a second time, I’ve just thought of another way that is a better fit for what you need. Though php doesn’t support multiple inheritance, and traits require php >= 5.4, you might want to consider adding a second “generation” (another level of children). The abstract class contains only those methods that are available to all, preferably with final keyword, or that only have 1 variation somewhere down the line (in which case, drop the final keyword and override the member function).

    As I’ve said before, I’m not that good in explaining this stuff, So I went on ahead an put together an example of how your classes could look like:

    abstract class User
    {
        public function __construct()
        {
            echo get_class($this).'<br/>';
        }
        final function forAll()
        {
            echo 'access for all';
        }
    }
    class TxtGroup extends User
    {
        public function __construct()
        {
            parent::__construct();
        }
        public function abstr()
        {
            echo 'TxtGroup specific';
        }
    }
    class ImgGroup extends User
    {
        public function __construct()
        {
            echo 'Same, but different for ImgGroup<br/>';
            parent::__construct();
        }
        public function abstr()
        {
            echo 'ImgGroup specific';
        }
    }
    class inst1 extends TxtGroup
    {
        public function __construct()
        {
            parent::__construct();
            if ($this instanceof TxtGroup)
            {
                echo 'Child member of: TxtGroup<br/>';
            }
            if ($this instanceof inst1)
            {
                echo 'Child instance of inst1 (itself)<br/>';
            }
            if ($this instanceof User)
            {
                echo 'grand-Child of User<br/>';
            }
        }
        public function objSpecific()
        {
            echo 'self explanatory<br/>';
        }
    }
    class inst2 extends ImgGroup
    {
        public function __construct()
        {
            parent::__construct();
            if ($this instanceof ImgGroup)
            {
                echo 'Child member of: ImgGroup<br/>';
            }
            if ($this instanceof inst2)
            {
                echo 'Child insance of inst2 (itself)<br/>';
            }
            if ($this instanceof User)
            {
                echo 'grand-Child of User<br/>';
            }
        }
    }
    $foo = new inst1();
    $bar = new inst2();
    

    See what I mean? Output:

    inst1
    Child member of: TxtGroup
    Child instance of inst1 (itself)
    grand-Child of User
    Same, but different for ImgGroup
    inst2
    Child member of: ImgGroup
    Child insance of inst1 (itself)
    grand-Child of User


    If you’re using the latest version of PHP, you have traits for that. There’s a lot of ways you can check which class is invoking the memberfunction. The easiest, IMO, is by starting your methods by checking the value of get_class($this);:

    abstract class Foo
    {
        public function who()
        {
            echo get_class($this);
        }
    }
    class bar extends Foo
    {
        public function __construct()
        {
            $this->who();
        }
    }
    $f = new bar();
    

    echo’s bar, so you can alter the abstract methods, and throw exceptions if necessary.

    The same construction can be used to overload certain methods, like this (terrible) example (tries to show/) shows:

    abstract class Foo
    {
        public function who()
        {
            $child =  explode('_',get_class($this));
            if (end($child) === 'whoExec')
            {
                return $this->whoExec();
            }
            echo 'this isn\'t for bar the bar instance';
            return $this;
        }
        private function whoExec()
        {
            if(!strstr('whoExec',get_class($this)))
            {
                return $this->who();
            }
            echo 'This methods mimics overloading -sort of';
            return $this;
        }
    }
    class bar_whoExec extends Foo
    {
        public function __construct()
        {
            $this->who();
        }
    }
    $f = new bar(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the content of file User.php <?php class My_Controller_Plugin_User extends Zend_Controller_Plugin_Abstract { public
import javax.ejb.EJB; public abstract class AbstractController<TEJB extends EntityEJB<TENTITY>, TENTITY extends EntityInterface> { @EJB protected
I've got a zend framework model: class User extends Zend_Db_Table_Abstract { protected $_name =
My model is like this class Foo(models.Model): user = models.ForeignKey(User) class Meta: abstract =
abstract class base { abstract public function test(); public function run() { self::test(); }
abstract class Base {} class A extends Base class B extends Base How do
public abstract class Request { public class Parameters { //Threre are no members here
I've got a pretty simple abstract class public abstract class AbstractServiceActions { @Autowired protected
I'm writing a class to handle a memcached object. The idea was to create
I have the following idea: Business object implemented as interface or abstract class with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.