picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.82k stars 616 forks source link

Cannot redeclare class Pico #127

Closed outrunthewolf closed 9 years ago

outrunthewolf commented 10 years ago

Hi there.

Using nginx, I get:

"Fatal error: Cannot redeclare class Pico in /home/pico/public_html/lib/pico.php on line 13"

Fixed this by commenting the require in index.php.

Do you not need the require because you're autoloading? Or is this something to do with nginx/php?

teuio commented 10 years ago

I am having similar redeclaration problem with nginx. Commenting out the require (require(LIB_DIR .'pico.php');) from index.php fixes the problem.

int3rlop3r commented 10 years ago

I dont think this has anything to do with nginx. I came across the same problem using apache.

outrunthewolf commented 10 years ago

A weird one :monkey_face:

andreburgaud commented 10 years ago

I just faced the same problem after installing a plugin via composer. Composer generates file vendor/composer/autoload_files.php with the following content:

<?php
// autoload_files.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
    $baseDir . '/lib/pico.php',
);

This conflicts with loading pico.php in index.php. I'm not sure what should be the best approach. For now commenting either line works. Any suggestions from the PHP experts?

pfiaux commented 10 years ago

Commenting one of them out is definitely the right approach. I would opt for the one in index.php.

Composer is actually configured to insert that statement which makes sense. If however you wanted to remove it from composer you'd have to go to composer.json and uncomment the following lines:

"autoload": {
    "files": ["lib/pico.php"]
}

Then when you run the install it should not generate the statement any more. But again I'd say the composer way is a bit more elegant.

outrunthewolf commented 10 years ago

would changing the line:

require(LIB_DIR .'pico.php');

to

require_once(LIB_DIR .'pico.php');

fix the issue?

scottzirkel commented 10 years ago

Same issue here. Changing to require_once cleared it up for me.

outrunthewolf commented 10 years ago

Made a p/r to update the index file, should patch it for now.

https://github.com/gilbitron/Pico/pull/141

hongster commented 10 years ago

Thanks @outrunthewolf. Can @picocms please accept his pull request?

iign commented 10 years ago

This works great for me. Thanks. Would be great to see it pushed by @picocms

picocms commented 10 years ago

Done, sorry about the delay.

iign commented 10 years ago

@picocms Thanks, mate!

outrunthewolf commented 10 years ago

@picocms Cheers dude