Skip to main content
Removed missing link.
Source Link
Paul
  • 4k
  • 2
  • 23
  • 38

The other option is making the autoloader aware of what it should have control over (what classes it should be able to load). You can see an example of what I mean here. Because we can have a stack of functions that provide autoloading we can only throw an exception if we know that the autoloader should have been able to load the class that was passed to it. Throwing an exception gives us more control over how it is handled than a fatal error.

The other option is making the autoloader aware of what it should have control over (what classes it should be able to load). You can see an example of what I mean here. Because we can have a stack of functions that provide autoloading we can only throw an exception if we know that the autoloader should have been able to load the class that was passed to it. Throwing an exception gives us more control over how it is handled than a fatal error.

The other option is making the autoloader aware of what it should have control over (what classes it should be able to load). Because we can have a stack of functions that provide autoloading we can only throw an exception if we know that the autoloader should have been able to load the class that was passed to it. Throwing an exception gives us more control over how it is handled than a fatal error.

Removed point #1 due to edit of question.
Source Link
Paul
  • 4k
  • 2
  • 23
  • 38
  1. How does it even work?Inconsistent Naming

    $filenameprotected $_observers = strtolowerarray($class) . $extension;;
    $file = $structureprotected .$structure;
    protected $extension;
    

Your autoload function then completely ignores $filename and uses $file (which is only the structure and extension). I can't see how it would load the file.

  1. Inconsistent Naming

    protected $_observers = array();
    protected $structure;
    protected $extension;
    
  1. Singleton is wrong
  1. Singleton is wrong
  1. getObject
  1. getObject
  1. Static causes Tight Coupling
  1. Static causes Tight Coupling
  1. How does it even work?

    $filename = strtolower($class) . $extension;
    $file = $structure . $extension;
    

Your autoload function then completely ignores $filename and uses $file (which is only the structure and extension). I can't see how it would load the file.

  1. Inconsistent Naming

    protected $_observers = array();
    protected $structure;
    protected $extension;
    
  1. Singleton is wrong
  1. getObject
  1. Static causes Tight Coupling
  1. Inconsistent Naming

    protected $_observers = array();
    protected $structure;
    protected $extension;
    
  1. Singleton is wrong
  1. getObject
  1. Static causes Tight Coupling
Minor fixes and clarifications.
Source Link
Paul
  • 4k
  • 2
  • 23
  • 38

Not being able to load a class that you are trying to use is a very serious error. If you want to use that class then not loading it is not an option. It is too late when you try to use it anand invoke the autoloader. You should not have done any checking beforehandwritten the code that was going to avoid usingrequire a bad class that you don't have.

There are a few options on how you can fail out of autoloading. The standard way is a fatal error. This provides limited options to handle the error. You can only do very basic things within a shutdown_handlershutdown function (set via register_shutdown_function).

It is very easy to display an error page when you catch an exception (This is the appropriate thing to do rather than try to recover from an autoloading failure). This exception gives the signal to the correct place (which is the higher up code that is making the call) rather than an observer which can only guess at what the current execution stack is.

  1. How does it even work?

    $filename = strtolower($class) . $extension; $file = $structure . $extension;

    $filename = strtolower($class) . $extension;
    $file = $structure . $extension;
    

Not being able to load a class that you are trying to use is a very serious error. If you want to use that class then not loading it is not an option. It is too late when you try to use it an invoke the autoloader. You should have done any checking beforehand to avoid using a bad class.

There are a few options on how you can fail out of autoloading. The standard way is a fatal error. This provides limited options to handle the error. You can only do very basic things within a shutdown_handler function (set via register_shutdown_function).

It is very easy to display an error page when you catch an exception (This is the appropriate thing to do rather than try to recover from an autoloading failure). This exception gives the signal to the correct place (which is the higher up code that is making the call) rather than an observer which can only guess at what the current execution is.

  1. How does it even work?

    $filename = strtolower($class) . $extension; $file = $structure . $extension;

Not being able to load a class that you are trying to use is a very serious error. If you want to use that class then not loading it is not an option. It is too late when you try to use it and invoke the autoloader. You should not have written the code that was going to require a class that you don't have.

There are a few options on how you can fail out of autoloading. The standard way is a fatal error. This provides limited options to handle the error. You can only do very basic things within a shutdown function (set via register_shutdown_function).

It is very easy to display an error page when you catch an exception (This is the appropriate thing to do rather than try to recover from an autoloading failure). This exception gives the signal to the correct place (which is the higher up code that is making the call) rather than an observer which can only guess at what the current execution stack is.

  1. How does it even work?

    $filename = strtolower($class) . $extension;
    $file = $structure . $extension;
    
Source Link
Paul
  • 4k
  • 2
  • 23
  • 38
Loading