2

I am trying to use Michelf's PHP implementation of Markdown.

I'm including his Markdown.php script with include() at the beginning of my main script, but when trying to use the class (be it for creating a new object or using a method directly), I get this:

Fatal error: Class 'Markdown' not found in [my main script]

The class Markdown is cleary defined in included Markdown.php however.

I've checked, of course, that the include works. I've tried placing Markdown.php in both my include_path and my main script's path, it doesn't change anything.

I am at a loss.

3
  • Look at markdown.php does it start with class Markdown { or function markdown Commented Aug 27, 2013 at 3:03
  • @DarylGill It's a namespaced class. Commented Aug 27, 2013 at 3:05
  • @Jack Indeed. That was the piece I missed. Commented Aug 27, 2013 at 14:45

1 Answer 1

3

Judging by the source file, you most likely forgot to import the class before using it:

use Michelf\Markdown;

// ...

$md = new Markdown();

Alternatively, you could use the canonical name:

$md = new \Michelf\Markdown();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I didn't know anything about namespaces. After you pointed it out I went to educate myself a bit, and now it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.