thinkphp5 formwork reflection class
[0] ThrowableError in ComposerLocator.php line 43 致命错误: Call to a member function findFile() on string
/**
* Returns a path to the file for given class name
*
* @param string $className Name of the class
*
* @return string|false Path to the file with given class or false if not found
*/
public function locateClass($className)
{
$filePath = $this->loader->findFile($className);
if (!empty($filePath)) {
$filePath = PathResolver::realpath($filePath);
}
return $filePath;
}
}
Can you please post the value of $this->loader?
@aik099 array(2) { [0]=> string(12) "think\Loader" [1]=> string(8) "autoload" } print var_dump($this->loader); in line 54
It appears, that you have custom autoloader (the think\Loader class) that is based on Composer's autoloader (extends Composer\Autoload\ClassLoader class), but not havingfindFile method.
How is that possible?
On the other hand maybe in PHP7 instanceof operator used in https://github.com/goaop/parser-reflection/blob/master/src/Locator/ComposerLocator.php#L33 is clever enough to work with callable representing an object and not actual object and that causes the issue to happen.
Now I've got it. According to docs on http://php.net/instanceof page (see Example #5 Using instanceof with other variables sub-section) it's expected instanceof operator behavior.
This way of autoloader is registered like this it will work:
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
But this won't work:
spl_autoload_register(array('ClassName', 'loadClass'), true, $prepend);
What we can change is to create instance of loader class if one we've found in autoloader registration turns out to be a string.
You can send a PR (+updated tests) for that.
Hi!
Am I right, that an additional extra check should be added to be sure that variable is object and not a string?
Almost. I think we won't loose anything if we try instantiation object of given autoloader class (when class name instead of object is given) and use it.
Just ignoring autoloaders, which are descendants of Composer autoloader but are registered in array('ClassName', 'autoload') form instead of array($this, 'autoload') form won't help much.