Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2008
    Location
    @ God's Own Country
    Posts
    57
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Question Problem with PHP class

    Hi guys,

    I am facing one problem with php class.

    I have to represent the inherited class dynamically. Unfortunately its not working. I have specified the code below, please go through the code and let me know any solution or any other equivalent method to represent the inherited class dynamically.

    first class page code
    class clsconfigs {
    //put your code here
    var $configs = array("driver"=>"mysql",
    "core"=>"clsmysqlcore",
    "user"=>"root",
    "pwd"=>"root",
    "db"=>"db_test");

    public function getConfigDetails(){
    return $this->configs;
    }
    }
    -------------------------------------------------------------------------

    second class page code
    require 'clsconfigs.php';
    $reflector = new ReflectionClass('clsconfigs');
    $arrConfigs = $reflector->getConfigDetails();

    class clsdbo extends $arrConfigs["core"] {
    //put your code here
    }

    -------------------------------------------------------------------------
    core class file code
    class clsmysqlcore {
    //put your code here
    }


    the first class clsconfigs will generate dynamically while installing the application. The 'core' value will change according to the selection of database at the installation time. we have separate core files for each databases those are supported by our application. So I have to represent the core value, which is the name of core class. That should inherited by the clsdbo class.


    Advance Thanks....
    ---
    By
    Sreejith.P.M

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Where do you get ReflectionClass from?
    I guess it should be
    PHP Code:
    $reflector = new clsconfigs(); 

  • #3
    New Coder
    Join Date
    Feb 2008
    Location
    @ God's Own Country
    Posts
    57
    Thanks
    3
    Thanked 5 Times in 5 Posts
    I have tried with reflection class, but unfortunately it didn't work...

    Can you please show me an example?
    ---
    By
    Sreejith.P.M

  • #4
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    example of what?
    I've asked you where did you get ReflectionClass. You haven't listed it in your code. so, post ReflectionClass here to check it works properly.

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,280
    Thanks
    12
    Thanked 343 Times in 339 Posts
    ReflectionClass is built into PHP.

    Quote Originally Posted by sreejithpm View Post
    PHP Code:
    class clsdbo extends $arrConfigs["core"] {
        
    //put your code here

    that certainly won’t work. it looks more like you have to use a Factory or Composite pattern to accomplish that.
    Last edited by Dormilich; 11-22-2010 at 06:59 AM.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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