Modularity in PHP

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Gambler wrote:Okay, now I get it. Thanks.
Though that is probably not the best implementation. I would separate the Registry and the Locator rather than having them all in one.
...
Gambler wrote:Does anyone know how to re-write my make() function without eval and reference loss?

Code: Select all

<?php
function & make($class, $args = array()){
    include_once("dir/$class.php"); //or something like this
    $argsCode = array();
    foreach (array_keys($args) as $key) {
        $argsCode[] = "\$args[$key]";
    }
    $code = "$obj =& new $class(" . join(', ', $argsCode) . ");";
    eval($code);
    return $obj;
}
?>
(#10850)
Post Reply