phix icon indicating copy to clipboard operation
phix copied to clipboard

Wrong autoloader version after pear installation

Open agvstin opened this issue 14 years ago • 2 comments

I followed the steps on phix-project.org to install phix using the pear installer. After installation trying to run phix throws the following error:

PHP Fatal error:  Call to undefined function psr0_autoloader_searchFirst() in /export/users/agusting/pear/phix on line 28
PHP Stack trace:
PHP   1. {main}() /export/users/agusting/pear/phix:0

Fatal error: Call to undefined function psr0_autoloader_searchFirst() in /export/users/agusting/pear/phix on line 28

Call Stack:
    0.0002     659704   1. {main}() /export/users/agusting/pear/phix:0

I did some digging and found that the function is nowhere to be found in the installed source code. However I found it in yours repositories: https://github.com/stuartherbert/Autoloader/blob/master/src/php/psr0.autoloader.php

But the file installed in my pear directory looks like this:

agusting@cobalt ~$ head -50 /export/users/agusting/pear/php/psr0.autoloader.php

// autoloader support
function __autoloader_normalise_path($className)
{
         $fileName  = '';
         $lastNsPos = strripos($className, '\\');

         if ($lastNsPos !== false)
         {
                $namespace = substr($className, 0, $lastNsPos);
                $className = substr($className, $lastNsPos + 1);
                $fileName  = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
         }

         return $fileName . str_replace('_', DIRECTORY_SEPARATOR, $className);

}

function __autoloader_init_namespace($namespace, $fileExt = '.init.php')
{
        static $loadedNamespaces = array();

        // have we loaded this namespace before?
        if (isset($loadedNamespaces[$namespace]))
        {
                // yes we have - bail
                return;
        }

        $path = __autoloader_normalise_path($namespace);
        $filename = $path . '/_init/' . end(explode('/', $path)) . $fileExt;
        $loadedModules[$namespace] = $filename;

        __autoloader_include($filename);
}

function __autoloader_init_tests($namespace)
{
        __autoloader_namespace($namespace, '.initTests.php');
}

function __autoloader_autoload($classname)
{
        if (class_exists($classname) || interface_exists($classname))
        {
                return FALSE;
        }

        // convert the classname into a filename on disk

// ....

I performed a search on github and couldn't find those functions. Maybe another package overwrote the file, but it was a clean installation on an empty pear directory, and I didn't install anything else after phix installation (if you know how to query pear about a file, I'll be happy to tell you who was the responsible :p ).

To solve that problem I replaced the file (included by the phix command line) with the latest version of the Autoloader component. And the following error showed up:

PHP Fatal error:  Class 'Phix_Project\ConsoleDisplayLib\StdOut' not found in /export/users/agusting/pear/php/Phix_Project/Phix/Context.php on line 97
PHP Stack trace:
PHP   1. {main}() /export/users/agusting/pear/phix:0
PHP   2. Phix_Project\Phix\Phix->main() /export/users/agusting/pear/phix:35
PHP   3. Phix_Project\Phix\Context->__construct() /export/users/agusting/pear/php/Phix_Project/Phix/Phix.php:70

Fatal error: Class 'Phix_Project\ConsoleDisplayLib\StdOut' not found in /export/users/agusting/pear/php/Phix_Project/Phix/Context.php on line 97

However, the ConsoleDisplayLib is installed on /export/users/agusting/pear/php/Phix/ConsoleDisplayLib and the namespace for it is Phix/ConsoleDisplayLib.

What I then realized, is that many references to Phix/ConsoleDisplayLib and Phix\CommandLineLib components's classes are done through the namespace Phix_Project/ConsoleDisplayLib and Phix_Project/CommandLineLib respectively.

Is this a pear packaging problem? Or is the code being migrated to a different namespace? I'll be happy to help, but don't know which namespace is correct.

agvstin avatar Oct 04 '11 22:10 agvstin

I did accidentally put ConsoleDisplayLib in the 'Phix' namespace, but that was back in August :( I can't explain how come this has appeared in your fresh install in October.

stuartherbert avatar Oct 16 '11 15:10 stuartherbert

I was thinking maybe there's an old version of that package in the PEAR Server... Or a wrong dependency configuration...

agvstin avatar Oct 16 '11 22:10 agvstin