...

View Full Version : Problem with PHP class



sreejithpm
11-21-2010, 08:30 AM
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....

poyzn
11-21-2010, 10:04 AM
Where do you get ReflectionClass from?
I guess it should be


$reflector = new clsconfigs();

sreejithpm
11-21-2010, 10:12 AM
I have tried with reflection class, but unfortunately it didn't work...

Can you please show me an example?

poyzn
11-21-2010, 11:11 AM
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.

Dormilich
11-22-2010, 07:55 AM
ReflectionClass (http://php.net/reflectionclass) is built into PHP.



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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum