Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class not found using Composer autoloading on Eclipse Neon #263

Closed
gizmecano opened this issue Mar 7, 2017 · 7 comments
Closed

Class not found using Composer autoloading on Eclipse Neon #263

gizmecano opened this issue Mar 7, 2017 · 7 comments

Comments

@gizmecano
Copy link

User of the classic version of PHP Markdown since more 5 years, I am currently trying to work with the most recent PHP Markdown Lib for a new project, using Composer on Eclipse Neon (with Composer Eclipse Plugin).

I think that I had not getting problem for configuring the require setting, as running Composer correctly updates dependencies using:

"require" : {
	"php" : ">=5.5",
	"michelf/php-markdown" : "~1.7"
},

As described in the Usage section of the documentation, I setup a PSR-0-compatible autoloader in my composer.json and generated the autoload file:

"autoload" : {
	"psr-0" : {
		"Michelf\\Markdown" : "vendor/michelf/php-markdown/Michelf"
	}
},

On my PHP file, I have simply included the following:

$input = file_get_contents('input.md');
use Michelf\Markdown;
$output = Markdown::defaultTransform($input);

All seem to be correctly recognized by Eclipse:

  1. namespace and class rightly appears as autocomplete propositions (first screenshot)
  2. library is displayed in the outline of the document as import declarations (second screenshot)

namespace-class

outline

But, despite all my testings with these settings, my page is still displaying:

Fatal error: Class 'Michelf\Markdown' not found

I supposed my problem is not really related with this previous issue, and I am not far to think that it is not a problem with the library as such, but rather that I made wrongly something during my configuration: I think having followed all the required steps but I do not find where is my potential mistake...

Thanks for helping.

@michelf
Copy link
Owner

michelf commented Mar 7, 2017 via email

@gizmecano
Copy link
Author

The formulation use \Michelf\Markdown; seems to be equally recognized by Eclipse (autocomplete feature and document outline, as displayed on previous screenshots), but I still get the fatal error...

@gizmecano
Copy link
Author

In addition, I wish to precise that, to ensure the autoload file was updated correctly, I have also executed the CLI dump-autoload command. Unfortunately, without more success at this time.

@gizmecano
Copy link
Author

I am continuing my tests, rebuilding my project from scratch to check I have rightly followed all the steps.

As I still get the same error, I have tried to use your Readme.php (as exposed in the Usage section of the documentation).

This time, I get the following messages:

Warning: require(Michelf\Markdown.php): failed to open stream: No such file or directory in ...
Fatal error: require(): Failed opening required 'Michelf\Markdown.php' (include_path='.;C:\php\pear') in ...

Although, if I paste the folder <Michelf> (and not <michelf> nor <php-markdown>) directly into the root of my project, the Readme.php correctly displays the content of Readme.md...

If I understand correctly, as the function spl_autoload_register is supposed to activate the __autoload queue (if the queue is not yet activated), I suppose that my problem is not really related to the implementation of your package but, indeed with something going wrong in my autoload settings.

@michelf
Copy link
Owner

michelf commented Mar 10, 2017

It's possible that the one-line autoloader bundled in the Readme.php file behaves a bit differently than the one from Composer when it does not find the file it attempts to load. But the "Fatal error: Class 'Michelf\Markdown' not found" could also mean you don't have any autoloader in place when attempting to use the class.

Note that you can bypass autoloading and directly include what you need with:

require_once 'Michelf/Markdown.inc.php';

I doubt very much this is a problem with the package. I'd have heard many more complains by now if this was the case.

@gizmecano
Copy link
Author

As nor the specific autoloader from Readme.php nor the default Composer system seem not to activate the class, I suppose that the problem is indeed that the configuration fails to correctly setup the PSR-0 autoloader (even if all seem to be correctly detected by the Eclipse IDE).

(I know that I can use the more classic system, such as require_once, but right now, I would like to try to use this kind of functionality).

I think I have to agree with you: my problem seems to be not directly related with your package. I suppose that I certainly made a mistake within my settings (even if I can not totally exclude an issue with Eclipse Neon PDT or its Composer support).

Accordingly, I close this issue (as not related with your package) and I ask a more generic question in order to find what could be the cause of this problem.

Thanks for your attention.

@gizmecano
Copy link
Author

It seems incredible, but I had only forgotten to add require __DIR__ . '/vendor/autoload.php'; at the beginning of my file...

It is so obvious that I don't know how I have missed that...

😒

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants