Skip to content

PHP 5.3 Namespace compability #5

@jaanush

Description

@jaanush

Just wondering if there is some plan on making it compatible with PHP 5.3 namespaces?

There are some issues with relative vs absolute scope (which can be overcome) but the main issue is with the factory calls (cant make a new_\My\Name\Space\Class function). Without a proper rewrite there are two quick ways to resolve this:

  1. Translate the namespace separator to something else - in this case '_':
function create($classname) {
    $classname = $this->scope->getImplementation($classname);
    $funcname=strtr($classname,'\\','_');
    if (isset($this->factory->{'new_' . strtolower($funcname)})) {
      return call_user_func($this->factory->{'new_'.$funcname}, $this);
    }
    if (method_exists($this->factory, 'new_' . $funcname)) {
      return $this->factory->{'new_'.$funcname}($this);
    }
    return $this->createThroughReflection($classname);
}
  1. Instead of checking for the existence of the 'new_' function call it and require the factory to have a __call catchall method that either handles the classname conversion or returns false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions