0

I'm having an unusual autoloading problem with my Zend website. Up until now autoloading has been working a treat. Now though, I added a new file the project and autoloading just can't find it. I've reduced the problem to the minimal test case and was wondering if anyone could help me out.

In my website I have a the usual directory structure, like so:

site/
  application/...
  library/
    Zend/...
    PHPUnit/...
    Ext/
      Extras/
        Test.php
      Service/
        Test.php

I've correctly set up auto loading (as per other helpful comments on StackOverflow) and registered the Ext_ namespace, which is proved by being able to correctly instantiate Ext_Extras_Test.

The problem comes when I try to instantiate Ext_Service_Test. Autoloading "failed to open stream". I've checked the correct spelling, listed the directory contents using find, ls, and the file explorer to make sure that the file exists in the correct place.

I just can't get it to &^%%£* find the file! Does anyone have any clues?

Pascal Dennerly
  • 212
  • 4
  • 9
  • Do you check if your file/folder have read access (unix permissions) ? – Aure77 May 24 '12 at 07:50
  • It's probably permissions related. Also try manually requiring in the file to see if you get the same error. – Tim Fountain May 24 '12 at 07:56
  • usually when I encounter this kind of problem it's because I'm trying to load classes that have a default loader. try changing 'Service' to 'services', there a some included defaults that are stealthed like 'mappers'. I have so far been unable to find the reference or the code for proof. – RockyFord May 24 '12 at 08:52

1 Answers1

1

Found it you are trying to override a resource autoloader, even though it's not specified I'm pretty sure this will effect all namespaces:

42.3.2. The Module Resource Autoloader Zend Framework ships with a concrete implementation of Zend_Loader_Autoloader_Resource that contains resource type mappings that cover the default recommended directory structure for Zend Framework MVC applications. This loader, Zend_Application_Module_Autoloader, comes with the following mappings:

forms/       => Form
models/      => Model
    DbTable/ => Model_DbTable
    mappers/ => Model_Mapper
plugins/     => Plugin
services/    => Service
views/
    helpers  => View_Helper
    filters  => View_Filter

As an example, if you have a module with the prefix of "Blog_", and attempted to instantiate the class "Blog_Form_Entry", it would look in the resource directory's "forms/" subdirectory for a file named "Entry.php".

When using module bootstraps with Zend_Application, an instance of Zend_Application_Module_Autoloader will be created by default for each discrete module, allowing you to autoload module resources.

RockyFord
  • 8,529
  • 1
  • 15
  • 21
  • I'm not sure about that. The resource autoloader mappings apply to clases in the `appnamespace` or in a module namespace. For classes on the `library` path with namespaces registered using something like `autoloadernamespaces[] = "MyLib"`, those mappings would _not_ apply. Isn't that right? Seems to me that the permissions issue in the question comments is more likely the issue. – David Weinraub May 24 '12 at 09:14
  • I agree those mappings 'should not' apply, that doesn't mean they won't, as for permissions, also something to check but if he made a new directory in a directory that already had proper permissions they 'should' inherit. Either way something to try. (It'll likely end up being something no one though of...) ;) – RockyFord May 24 '12 at 09:21
  • That's the one. I just moved it to applications/services (with the appropriate renaming) and everything just popped back in to life. Thanks for your help! – Pascal Dennerly May 24 '12 at 22:23