| 
	
 | 
 Posted by  grossespinne on 06/22/07 22:18 
Hi everybody! 
I have been thinking over the following problem: 
there are three classes: PageBase, which is the base class, PageA and 
PageB which are the subclasses of PageBase. 
In the index.php file I have a variable which I like to hold either an 
instance of PageA or PageB depending on the query string that is 
passed to index.php (e.g: if I get the query index.php?content=a, I 
need an instance of PageA, but if I get the query: index.php? 
content=b, an instance of PageB is needed) 
 
Until now I found two solutions, but I am not satisfied with either of 
them: 
- use a switch structure 
- or use eval: 
 
$pageType = isset($_GET["page"]) ? $_GET["page"] : "PageBase"; 
$thePage = eval("return new $pageType();"); 
 
My question is whether a more object-oriented way exists to solve the 
problem. 
 
TIA
 
  
Navigation:
[Reply to this message] 
 |