GithubHelp home page GithubHelp logo

Possible Autoloader problem? about predis HOT 9 CLOSED

predis avatar predis commented on June 15, 2024
Possible Autoloader problem?

from predis.

Comments (9)

nrk avatar nrk commented on June 15, 2024

I've never mixed include_path with autoloading, so I'm not really sure what to expect out of it. I'll try that later, in the meanwhile it's probably a stupid question but does /usr/share/php/Predis/Profiles/ServerVersion24.php actually exist (it should, but since it's a weird issue...).

from predis.

carrier avatar carrier commented on June 15, 2024

Just a filename error.
filename is autoload.php, while Predis tries to load "Autoloader.php".

Just change to require autoload.php, or rename autoload.php to Autoloader.php and it should work.

from predis.

nrk avatar nrk commented on June 15, 2024

@persandiex I tried to reproduce your issue using the same sequence of lines (the use \Predis; is useless here BTW) but I had no luck:

php > require 'Predis/Autoloader.php';
php > use \Predis;
php > Predis\Autoloader::register();
php > $r = new Predis\Client();
php > $r->ping();
php > echo $r->ping();
1
php > 

What's strange is that the autoloader does indeed work, or you would get an error as soon as PHP tries to load the Predis\Client class, not on the server profile class which comes at a later stage and after a few more classes. Without further details, I can't think of anything else other than a misconfiguration of your PHP environment.

@carrier autoload.php is just an utility file in the repository used to run examples and the test suite, what @persandiex did by requiring Predis/Autoloader.php is actually correct.

from predis.

nrk avatar nrk commented on June 15, 2024

@persandiex I couldn't reproduce even when trying with a PEAR installation of Predis. Any update on your issue?

from predis.

nrk avatar nrk commented on June 15, 2024

I'm closing this issue since no feedback has been provided for a month and I couldn't reproduce it. Feel free to comment with more details if you have some.

from predis.

manuelflara avatar manuelflara commented on June 15, 2024

Hello. I'm having the same issue. I've been able to figure out a workaround, but there must be something I'm doing wrong.

Basically, what happens is this. Check out how this method starts:

public function autoload($className)
{
    if (0 !== strpos($className, $this->_prefix)) {
        return;
    }

If I echo every $className that goes through there, this is what I get:

Predis\Client
Predis\ClientOptions
Predis\Options\ClientProfile
Predis\Options\Option
Predis\Options\IOption
Predis\Options\ClientConnectionFactory
Predis\Options\ClientCluster
Predis\Options\ClientPrefix
Predis\Profiles\ServerProfile
Predis\Profiles\IServerProfile
Predis\Commands\Processors\IProcessingSupport
\Predis\Profiles\ServerVersion24

And bam, here I get an error. You see the difference? ServerVersion24 starts with a backslash while the others don't. I think it works when you do "new \Predis\Class" but it doesn't work (the same thing happens) when Predis tries to autoload a classname that was defined in a text string:

        '2.4'     => '\Predis\Profiles\ServerVersion24',

If I mass-replace '\Predis with 'Predis (take out initial backslashes in the namespace of classes in strings), then everything works like a charm.

Any idea what could be happening? Because I'm sure this doesn't happen to everyone. I'm using Redis 2.4, OSX, Predis v0.7.0 and PHP 5.3.2.

Thanks

from predis.

nrk avatar nrk commented on June 15, 2024

@manuelflara thanks for adding more details to this issue, I never had the chance to see this error myself so I couldn't even try to perform some debugging. Fortunately those useless backslashes were removed with commit d9b95d0 just a few days before the release of Predis v0.7.0 as stable, everything should be OK now. Upgrading from a dev version of v0.7.0 is recommended anyway since a few bugs were fixed in the last rush before going stable with the v0.7 branch.

I'm almost sure this is a bug of PHP, but as far as I remember I never encountered this error when using PHP 5.3.2 on Linux so I guess if it's something related to older versions of PHP on OS X. Do you have any opcode cache module or the suhosin patch/module loaded?

from predis.

manuelflara avatar manuelflara commented on June 15, 2024

I was actually surprised yesterday when I downloaded 0.7 again and this time worked! Thanks for the comment :)

from predis.

sandro-tassa avatar sandro-tassa commented on June 15, 2024

Hi,
this work fine for me on Centos and PHP7:

require 'Predis/Autoloader.php';
Predis\Autoloader::register();
$client = new Predis\Client();

from predis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.