SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict eanimator's Avatar
    Join Date
    Sep 2005
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calling Class name

    PHP Code:
    class userController extends FrontController{
        
    }

    class 
    FrontController{
        function 
    __construct(){
          
    /* calling class name without explictly passing __CLASS__ to the constructor. 
         */
        
    }

    Is there's any way that I can find which class extends the "FrontController".

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Maybe not correct, I'm a Reflection API beginner.

    PHP Code:
    <?php
    class ParentObject
    {
        public function 
    getExtendingObjectName()
        {
            
    $oRefl = new ReflectionObject($this);
            return 
    $oRefl->isSubclassOf(__CLASS__) ? $oRefl->getName() : null ;
        }
    }

    class 
    SisterObject extends ParentObject
    {

    }

    $oFamilyMember = new ParentObject();
    echo 
    $oFamilyMember->getExtendingObjectName(); #null

    $oFamilyMember = new SisterObject();
    echo 
    $oFamilyMember->getExtendingObjectName(); #SisterObject
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,398
    Mentioned
    65 Post(s)
    Tagged
    1 Thread(s)
    Maybe I'm missing some technicality but why would get_class($this) not do what you want?
    Salathe
    Software Developer and PHP Manual Author.

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    If you are needing to find what class is calling or extending another class then there is something wrong with your design.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Addict eanimator's Avatar
    Join Date
    Sep 2005
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the parent class, I am trying to know its child class which extended it.

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Why? Why would you need to do something like that? Whatever it is you are doing, you should take that as a sign you are going the wrong way.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  7. #7
    SitePoint Addict eanimator's Avatar
    Join Date
    Sep 2005
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying to know which controller extended the front controller

    i.e.
    http://www.mysite.com?control=home

    PHP Code:
    class homeController extends FrontController{

    }


    class 
    FrontController{
     function 
    __construct(){
      
    /*
       To know the name of controller.
      */ 
      
    $current_class  __CLASS__ // not needed.
    }


  8. #8
    SitePoint Addict eanimator's Avatar
    Join Date
    Sep 2005
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SilverBulletUK View Post
    Maybe not correct, I'm a Reflection API beginner.

    PHP Code:
    <?php
    class ParentObject
    {
        public function 
    getExtendingObjectName()
        {
            
    $oRefl = new ReflectionObject($this);
            return 
    $oRefl->isSubclassOf(__CLASS__) ? $oRefl->getName() : null ;
        }
    }

    class 
    SisterObject extends ParentObject
    {

    }

    $oFamilyMember = new ParentObject();
    echo 
    $oFamilyMember->getExtendingObjectName(); #null

    $oFamilyMember = new SisterObject();
    echo 
    $oFamilyMember->getExtendingObjectName(); #SisterObject
    ?>

    //Working. Thank you
    $oRefl = new ReflectionObject($this);
    return $oRefl->isSubclassOf(__CLASS__) ? $oRefl->getName() : null ;


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •