2010-03-19

Namespaced out of nothing...

I am currently trying to debug a very strange error I am seeing.

The Stage

FLOW3 in it's current SVN version, PHP 5.3.2 (MacPorts) on OSX 10.6.2, SwiftMailer 4.0.6

The Setup

I created a SwiftMailer package, in that exists a class that extends SwiftMailer's Message class. Now I ask the object manager in FLOW3 for an instance of that class. That all works fine when the static object container for FLOW3 has not yet been written. If the static object container is used, I get:

The Problem

But the problem is cause by something inside PHP, it seems, which is triggered somehow when FLOW3 is involved. Does it push PHP over it's edge? Here is the error I get:
Fatal error: Interface 'F3\Party\Domain\Model\Swift_Mime_HeaderSet' not found in /.../Swift/Mime/SimpleHeaderSet.php on line 23
Line 23 of SimpleHeaderSet.php looks like this:
class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
Now, there is no namespace declaration in that file, so why on earth does PHP want to use F3\Party\Domain\Model\Swift_Mime_HeaderSet? I could not believe what I was seeing, and added some lines echoing __NAMESPACE__ to some files involved. This is the result:
namespace in SwiftMailer\Message constructor: F3\SwiftMailer
namespace in Swift_Message constructor:
namespace in SimpleHeaderSet file: F3\Party\Domain\Model
Message, check; Swift_Message, check; SimpleHeaderSet, .... WTF? Here is the backtrace to see what happens:
F3\FLOW3\Object\Container\StaticObjectContainer->c0294( ??? ) ../AbstractObjectContainer.php:0
F3\SwiftMailer\Message->__construct( ) ../StaticObjectContainer.php:4747
Swift_Message->__construct( ???, ???, ???, ??? ) ../Message.php:44
Swift_DependencyContainer->createDependenciesFor( ??? ) ../Message.php:38
Swift_DependencyContainer->_resolveArgs( ??? ) ../DependencyContainer.php:121
Swift_DependencyContainer->_lookupRecursive( ??? ) ../DependencyContainer.php:321
Swift_DependencyContainer->lookup( ??? ) ../DependencyContainer.php:345
Swift_DependencyContainer->_createNewInstance( ??? ) ../DependencyContainer.php:105
ReflectionClass->__construct( ??? ) ../DependencyContainer.php:277
Swift::autoload( ??? ) ../Swift.php:0
require_once( '/.../Swift/Mime/SimpleHeaderSet.php' ) ../Swift.php:44
As you can see, the namespace in Message is fine, as is the case in Swift_Message. Now the Swift_DependencyContainer comes into play and when ReflectionClass' constructor fires an autoloading request for Swift_Mime_SimpleHeaderSet the namespace magically changes to F3\Party\Domain\Model (the namespace is output in the first LoC of that file!).

I wrote a small script consisting of 5 require() statements and two lines of code to instantiate a Message using the static object container, but of course that works like a charm.

Any Hints

on how to debug this further are highly welcome. But I am rather certain that not anyone else on our planet ever had a similar problem. Do they use PHP and FLOW3 on the ISS?