Bug #53533

Class reflection assumes reverse PSR-0, can lead to fail in autoloader

Added by Christian Jul Jensen over 1 year ago.

Status:New Start date:2013-11-11
Priority:Should have Due date:
Assigned To:- % Done:

0%

Category:Reflection
Target version:-
PHP Version: Complexity:hard
Has patch:No Affected Flow version:Git master

Description

When gathering info about a package Flow currently assumes PSR-0 as bijective which is not the case.

Ie.

The file Pheanstalk/PheanstalkInterface.php does not necessarily hold the class \Pheanstalk\PheanstalkInterface, this situation has already been handled for files containing sideeffects rather than classes fx. autoload.php

The problem is that according to PSR-0 the file can hold the class \Pheanstalk_PheanstalkInterface, and thus the following can happen;

1. Flow analyzes filesystem and adds Pheanstalk/PheanstalkInterface.php to files to be reflected, expecting \Pheanstalk\PheanstalkInterface.
2. During the reflection some other class implements \Pheanstalk_PheanstalkInterface and the autoloader correctly loads this from Pheanstalk/PheanstalkInterface.php
3. The autoloader reaches Pheanstalk/PheanstalkInterface.php for inclusion and fails with 'Fatal error: Cannot redeclare class Pheanstalk_PheanstalkInterface'

This is not trivial to handle since the file could actually hold the expected namespaced class.

Possible ways to fix it:
  • During compiletime let ClassLoader notify ReflectionService on included files so it can be removed from further reflection
  • Let ReflectionService pre-analyze files for expected classes.

Also available in: Atom PDF